DAO, Spring and Hibernate

Posted by EugeneP on Stack Overflow See other posts from Stack Overflow or by EugeneP
Published on 2010-03-15T12:25:40Z Indexed on 2010/03/15 12:29 UTC
Read the original article Hit count: 404

Filed under:
|
|
|

Correct me if anything is wrong.

Now when we use Spring DAO for ORM templates, when we use @Transactional attribute, we do not have control over the transaction and/or session when the method is called externally, not within the method.

Lazy loading saves resources - less queries to the db, less memory to keep all the collections fetched in the app memory.

So, if lazy=false, then everything is fetched, all associated collections, that is not effectively, if there are 10,000 records in a linked set.

Now, I have a method in a DAO class that is supposed to return me a User object. It has collections that represent linked tables of the database. I need to get a object by id and then query its collections.

Hibernate "failed to lazily initialize a collection" exception occurs when I try to access the linked collection that this DAO method returns.

Explain please, what is a workaround here?

© Stack Overflow or respective owner

Related posts about java

Related posts about dao