I too am having the same problems. On most relationships, I get back the real object but there's a select few relationships where I get back the proxy object and it causes havoc. Not only in my code by I can't merge it back into the EntityManager to save changes either (I'm using EJB 3.0).
I find it frustrating that I can't find more definitive information on what is going on and how to find an optimal solution.
From my experience there are only two sure ways to solve this: using lazy=false, or using JOIN FETCH queries, although these can introduce problems of their own.
I don't like using EAGER relationships when I don't have to however the few places where I am having trouble are on N-to-1 relationships so it shouldn't have a lot of unnecessary objects being loaded.
I find it interesting that Hibernate folks themselves suggest setting lazy=false as a solution to this when elsewhere in their documentation they strongly suggest avoiding eager relationships since they may load too many unneeded objects -- possibly the entire database in a worst case scenario.
I wish I could find a better solution but so far I can't.
|