views:

554

answers:

2

Hi!

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.

A: 

Did you try evicting the Object from the Session ?

Narayan
How and when(where) would you do that to achieve the goal I have stated in the question?
artemb
A: 

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

artemb