如何强制 JBoss 4.2.3 清除每个请求的 hibernate 会话缓存?
在我看来,JBoss 重用实体管理器和底层休眠会话来处理多个请求。我运行了一个测试,证明在某些情况下,即使只是使用 em.find() 获取实体的状态也可能已过时。
如何禁用此行为并强制清除或丢弃使用过的会话,以确保每个请求都通过清除缓存进行处理?
UPD:
这是一个示例案例。
HTTP 请求 1. 会话 Bean 创建一个实体实例并将其存储,并将字段“A”设置为值 1。 持久化实体获取 ID = 4。
HTTP 请求 2. 会话 Bean 查找 ID = 4 的实体,设置其将“A”字段的值设置为 2 并保存。
HTTP 请求 3. 会话 bean 查找 ID = 4 的实体并检查其字段“A”。如果值为 1,则执行一件事;如果值为 2,则执行另一件事。
如果请求 3 中的 EM 恰好与请求 1 中的 EM 相同,则会出现不良行为。我已经对此进行了测试并得到了大约。 10%的案例失败。
It seems to me that JBoss reuses entity managers and the underlying hibernate sessions for multiple requests. I have run a test which proves that in some cases the state of an entity may be out-dated even if it is just fetched using em.find()
.
How can I disable this behaviour and force to clear or throw away used sessions to ensure that each request is handled with clear cache?
UPD:
Here is an example case.
HTTP request 1. A session bean creates an entity instance and stores it with field "A" set to value 1. The persisted entity gets ID = 4.
HTTP request 2. A session bean looks up an entity with ID = 4, sets its field "A" to value 2 and saves it.
HTTP request 3. A session bean looks up an entity with ID = 4 and checks it's field "A". If the value is 1 it does one thing, if it is 2 it does another thing.
In case if the EM in request 3 happens to be the same as in request 1, an undesired behavior occurs. I have tested this and got approx. 10% cases of failure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您尝试过 从 会话 ?
Did you try evicting the Object from the Session ?
好吧,我明白了。 JBoss 正确处理会话,我的测试中有一个错误 =) 抱歉,感谢您的帮助
Ok, I figured this out. JBoss handles sessions correctly, there was a bug in my test =) Sorry, and thanx for your help