How to force JBoss 4.2.3 to clear hibernate's session cache for every request?

拥有回忆 提交于 2019-12-11 03:13:30

问题


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.


回答1:


Did you try evicting the Object from the Session ?




回答2:


Ok, I figured this out. JBoss handles sessions correctly, there was a bug in my test =) Sorry, and thanx for your help



来源:https://stackoverflow.com/questions/1293429/how-to-force-jboss-4-2-3-to-clear-hibernates-session-cache-for-every-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!