I have a problem related to getting stale (cached?) data from Hibernate
EntityManager injected to SFSB (so I'm using it through JPA) using
extended persistence context. Apache Geronimo 2.3.1 is used as
the Java EE 5 container.
I have disabled query and 2nd level caches in the configuration and
Hibernate logs state both caches as being disabled.
The problem occurs randomly: after persisting and modifying some data,
the EntityManager starts to return old instances/values for the objects.
The application is a web application and I'm creating new Session Beans for
each request through JNDI lookups, and a new EntityManager gets injected
for each request, so that should not be the problem (I've even checked the
object hashcodes of the injected EntityManagers and Session Beans).
Here's a log excerpt from a simple "SELECT * FROM CONFIGURATION" query.
This fetches all instances of ConfigurationAttribute class that you can see in
the debug log - the contents of the class don't matter. The class does not
have any mappings to other EntityBeans, just plain string values.
See the log:
http://pastebin.com/m1e308e8f
The weird thing is that on line 101 I can see "[Printer] listing entities:" and
then a list of old cached instances of the objects (before the query is
executed). Why does Hibernate store these objects and why do newly injected
EntityManagers have (managed?) objects inside them ?
Although Hibernate then makes the query to the database, it seems to return
the old instances anyway... and it does this randomly!
I wonder if I should call EntityManager.clear() in SFSB initialization or is there
something else to know about injected EntityManagers...?
Hibernate version:
3.3.1
Apache Geronimo 2.3.1 as Java EE 5 container
Mapping documents:
None.
Code between sessionFactory.openSession() and session.close():
The code uses container-managed injected EntityFactory.
Full stack trace of any exception that occurs:
None.
Name and version of the database you are using:
MySQL 5.0
The generated SQL (show_sql=true):
On line 131 of the log:
Code:
[SQL] select configurat0_.ID as ID12_, configurat0_.NAME as NAME12_, configurat0_.VALUE as VALUE12_, configurat0_.TYPE as TYPE12_ from CONFIGURATION configurat0_
Debug level Hibernate log excerpt:
For full log see:
http://pastebin.com/m1e308e8f