[b]Hibernate version:[/b]
2.1.6
I have to use psuedo code to express my problem since I'm using spring and our own framework.
I've set the hibernate property hibernate.cache.use_query_cache to true.
I've set the setCacheable to true for Criteria object for me get and getEager routines.
Here is my calling code. The only difference between getEager and get is that for getEager we use criteria.setFetchMode("address", FetchMode.EAGER);
startTransaction();
Prospect prospect =
prospectDao.get(userSession, prospectDAOTest.getExistingId());
Prospect prospect2 = prospectDao.getEager(userSession, prospectDAOTest.getExistingId(), "address");
commitTransaction();
prospect2.getAddress().toString() // throws Could not initialize proxy - the owning Session session
SEVERE: Exception initializing proxy
net.sf.hibernate.HibernateException: Could not initialize proxy - the owning Session was closed
at net.sf.hibernate.proxy.LazyInitializer.initialize(LazyInitializer.java:47)
at net.sf.hibernate.proxy.LazyInitializer.initializeWrapExceptions(LazyInitializer.java:60)
at net.sf.hibernate.proxy.LazyInitializer.getImplementation(LazyInitializer.java:164)
at net.sf.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:108)
at fivesquare.common.data.model.crm.Address$$EnhancerByCGLIB$$586aa3af.toString(<generated>)
at fivesquare.common.data.dao.impl.BaseHibernateDAOTest.testCaching2(BaseHibernateDAOTest.java:74)
This is what I think is happening. The first retrieval of my prospect record doesn't include the fetching of the address. My second retrieve of the prospect record retrieves the cached result and ignores the fetch portion of the cached query. Thus the address object doesn't get initialized.
Is this a bug or an unfortuate side affect of caching results in the session?
Dino
|