java - LazyInitializationException when Persisting newly created Entity -
i have entity has manytomany relationship entity. let child has collection of hobbies. whenever want create new child, this:
child child = new child(); list<hobby> hobbies = hobbiesdao.retrieveall(); //get hobbies database child.sethobbies(hobbies); // error thrown here childdao.create(child); // persist database a lazyinitializationexception thrown. think because newly created child entity not yet attached session? how can attach newly created entity session not throw exception when adding related entities. thanks.
define hobies eagerly loaded unless needed lazily loaded hibernate defaultly
@manytomany(fetch=fetchtype.eager) public list<hobby> gethobbies() { return hobbies; }
Comments
Post a Comment