hibernate和ehcache复制
我正在研究节点之间的缓存复制解决方案
节点 A - 主节点=> Hibernate+数据库+Ehcache作为二级缓存
节点B-区域节点=> Ehcache 作为主缓存。没有休眠
节点B仅用作查询的近邻缓存。
现在我正在更新节点 A 中的数据(例如 SudentInfo),它会被正确持久化和缓存。在复制方面(我使用的是JMS),它向节点B发送一条消息。但问题是,它发送的消息是实例CacheEntry(deep Inside Element),没有办法复活原始对象(StudentInfo)。我在节点 B 中得到的是 CacheEntry,其中包含 Students 的一些属性,但实际上不是 Student 对象。
请注意,我不需要节点 B 中的 Hibernate 会话/持久化,节点 B 仅用于快速查询,持久化是通过节点 A 完成的。 那么有人尝试过这样的解决方案吗? 有什么方法可以将 CacheEntry 转换为实际对象吗? 或者告诉 ehcache 复制原始对象而不是 CacheEntry。
感谢您的帮助
I am working on a cache replication solution between nodes
Node A - master node => Hibernate + Database + Ehcache as secondary cache
Node B - regional node=> Ehcache as prmiary cache. no Hibernate
Node B is used only as near-by cache for query.
Now I am updating data (Say SudentInfo) in Node A, it gets persisted and cached correctly. On replication side (I am using JMS) it sends a message to Node B. But the problem is, the message it sends is of instance CacheEntry(deep Inside Element), there is no way to resurrect the original object (StudentInfo). What I got in node B is CacheEntry with some attributes of Students but not actually an Student Object.
Please note that I don't need Hibernate session/persistence in Node B, node B is only for fast query, persistence is done through Node A.
So has anybody tried any solution like this?
Is there any way to convert CacheEntry to actual object?
or Tell ehcache to replicate original object rather than CacheEntry.
Thanks for the help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“Ehcache作为二级缓存”是什么意思?作为二级缓存?
因为如果是这样的话,那么被复制的对象就不是一个对象,它是Hibernate用来存储对象的数据,它本质上相当于存储在数据库中的行级数据。
看一下这篇文章,它解释了二级缓存中的内容:
真正理解Hibernate二级缓存和查询缓存
我对你的问题是- 为什么不配置节点 B 与数据库通信 - 那么你就有了一个同质的设置。如果缓存恰好有效,那么很好,您将获得缓存的值并且不会访问数据库,如果没有,您将访问数据库。
除非存在某些拓扑原因,否则您无法执行此操作 - 我认为使用相同的配置/设置运行两个节点会容易得多。
What does "Ehcache as secondary cache" mean? As a second level cache?
Because if that's the case, then the object that is replicated is not an object, it's the data that Hibernate uses to store the object, it's essentially equivalent to the row level data stored in your database.
Take a look at this article, it explains what's in the second level cache:
Truly Understanding the Hibernate Second-Level cache and Query cache
My question to you would be - why not configure node B to talk to the database - then you have a homogoneous setup. If caching happens to be working - then great you get cached values and don't hit the DB - and if not you hit the DB.
Unless there is some topological reason you can't do this - it would be a lot easier in my opinion to just run both nodes with the same configuration/setup.