如何强制JBoss 4.2.3为每个请求清除hibernate的会话缓存? [英] How to force JBoss 4.2.3 to clear hibernate's session cache for every request?
问题描述
在我看来,JBoss重复使用实体管理器和底层hibernate会话来处理多个请求。我已经运行了一个测试,证明在某些情况下,实体的状态可能会过时,即使只是使用 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碰巧与请求中的EM相同1,发生不希望的行为。我测试了这一点,并得到了约。 10%的失败案例。
好的,我明白了这一点。 JBoss正确处理会话,在我的测试中有一个错误=)对不起,还有thanx的帮助
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.
Ok, I figured this out. JBoss handles sessions correctly, there was a bug in my test =) Sorry, and thanx for your help
这篇关于如何强制JBoss 4.2.3为每个请求清除hibernate的会话缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!