This is my first port to the Hibernate forum, but I'm at my wits end with a particular issue.
We use Hibernate 3.3.1 and the Java Persistence API.
In an attempt to simplify persistence tasks for the other developers, we've hidden the EntityManager behind our own API. Using generics, we've managed to create an API that exposes a save(), delete(), and load() method for each of our domain objects.
Of course, the above means that each transaction is atomic in the sense that if I save a domain object, the session is opened and closes only for the life of the method call (i.e. save, delete, and load).
Since we use lazy loading exclusively, the above is problemetic, but was solved by re-attaching detached objects to the session once a LazyInitializationException was encountered.
From what I've read online, the refresh() method provided by the JPA API does not work well, so we relaxed our JPA only rule and used the following.
manager = PersistenceManager.getEntityManagerFactory().createEntityManager();
((Session)manager.getDelegate()).refresh(aDomainObject);
// initialize object by accessing a method (i.e. force proxy to load object)
aDomainObject.getId();
It seemed to work perfectly but if I view the object using the Eclipse debugger, none of the primitive fields were loaded (i.e. null).
The strange thing is that if I use a System.out.println() and call the getter of one of those primitives, it does print out the values.
I need to know why the Hibernate refresh() is not loading the object properly and how to correct the issue.
Thanks in advance :)
P.S. running the test with hibernate.show_sql = true indicates that the select is executed to retrieve the appropriate data. It just seems that what's returned from the database is not re-associated with the object. I wonder if caching is getting in the way.
|