throws Lazy:
Code:
Part part = ((ReviewPart)review.getReviewParts().iterator().next()).getPart();
works fine:
Code:
Part part = (Part) session.iterate("SELECT r.part FROM ReviewPart r WHERE r.review = ?", review, Hibernate.entity(review.getClass())).next();
Quote:
Why would the second snippet cause a lazy exception? Nowhere are you doing anything that would cause lazy data to get loaded.
The 2nd snippet is the one that works, no problem.
Quote:
In the first snippet, you opened a session, used it to retreive a "review", and then closed the session. You then attempted to read across "review"'s reviewParts collection. Is that correct? Is Review.reviewPart mapped as lazy? Or is Review mapped with a proxy?Either of those would explain the exception.
2nd case works fine. 1st case throws lazy. All the collections are lazy. Both do this:
1.) open a session. (createSession(); session.lock(review, LockMode.NONE);)
2.) do some work. (starting with snippets 1 or 2).
3.) close the session. (session.connection.commit(); session.close();)
Later, I open a new session, then access a lazy collection of Part:
Code:
reviewPart.getPart().getPrices();
When I use the first version, the prices bag is owned by the old session.
When I use the second version, the prices bag is owned by the new session.
Thanks!