xiaodududu / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Lazily loaded collections has no session if method is not marked @Transactional #765

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Description of the issue:

Encountered a problem with how lazy loaded collections were workng. When I 
request collection data in the processing I'm getting:
{{{
org.hibernate.LazyInitializationException: failed to lazily initialize a 
collection of role: ..., no session or session was closed
}}}

I've found that there's no session in hibernate's PersistentBag I access. I've 
tried to mark method as @Transactional and it worked to my confusion.

I really dislike the solution as my *data-reading* method may now modify 
underlying data as a side-effect.

Steps to reproduce:
1. Create a class with lazily loaded collection (N-N in my case).
2. Query the data so the lazily loaded collection field wasn't fetched
3. Try to iterate over collection
4. org.hibernate.LazyInitializationException is thrown

Guice-Persist 3.0
Hibernate 3.6.10.

Original issue reported on code.google.com by alex.che...@gmail.com on 19 Aug 2013 at 3:18