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

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -