2 个独立的 Web 应用程序如何与 Hibernate 共享二级缓存?
我有 2 个网络应用程序。
我希望它能够访问与 Hibernate 相同的共享数据库,并且我想在每个数据库中使用二级缓存。但我希望第二个 Web 应用程序能够看到第一个 Web 应用程序的修改。
我不确定是否理解,但是 Hazelcast 是满足我需求的解决方案吗?
我能够像以前一样使用 Spring 使用该解决方案管理事务吗?
谢谢。
I have 2 web applications.
I want it to access to the same shared database with Hibernate and i want to use a second level cache in each. But i want the second web application to be able to see the first web application's modifications.
I am not sure to have understood but is Hazelcast a solution for my need ?
Will i be able to manage transactions as before with Spring with that solution?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为你让事情变得比需要的更加复杂。只需将两个 Web 应用程序设置为使用 select 语句提取数据,每当您修改其中一个页面上的数据(使用更新)时,都会进行回发。
这样,无论哪个页面进行更改,页面都会回发,并且当其他页面加载时,更改已经存在。如果您使用 ajax 来避免回发,这也应该有效。
I think you are making this more complicated than it needs to be. Just set up both web apps to pull in data using a select statement, and whenever you modify data (using an update) on one of the page, do a post back.
This way no matter which page makes a change, the page posts back and when the other page loads the change is already there. This should also work if you are using ajax to avoid post backs.
去做就对了。应用程序对数据库所做的任何更改对于读取该数据库的任何其他应用程序都应该是可见的。一旦提交了更改,它应该保存在硬盘上,并且从硬盘驱动器读取数据库的任何其他人都应该看到它。
Just Do It. Any change that an application makes to a database should be visible to any other application that reads that database. Once a change is committed, it should be on the hard drive, and anybody else who reads the database from the hard drive should see it.
您认为为什么不能拥有两个独立的会话工厂?这不会导致任何问题,除非您使用非集群二级缓存来存储读写实体。
Why do you think you can't have two separate session factories? This won't cause any problem, except if you're using a non-clustered second-level cache to store read-write entities.
为什么不呢?除非您设置了 刷新模式 改为
MANUAL
,应该没有问题。典型设置为COMMIT
或AUTO
。使用第二级可能会出现任何进一步的问题。缓存。如果您的应用程序服务器没有 JTA 环境,请避免这种情况。
PS:hibernate设置可以通过spring来配置,但也可以通过任何其他方式完成。
Why not? Except you have set the flush mode to
MANUAL
, there should be no problem. Typical setting isCOMMIT
orAUTO
.Any further problems can occur using a second level cache. Avoid this if your app server has no JTA environment.
PS: The hibernate settings can be configured by spring, but it can be done any other way.