This week's book giveaway is in the Testing forum. We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line! See this thread for details.
Hi I have a Dept table with one-to-many relation with employee table and employee table with many-to-one relation with Dept table. When I tried to map two employees to the same Dept I got "NonUniqueObjectException". So I changed the hibernate mapping file from lazy="false" to lazy="true" in both the Dept and Employee hbm.xml files. This solved my problem.
But now when I try to add a new Employee to a Dept which is already assosiated with the other Employees, I got "LazyInitializationException". I know its because of the lazy="true". But when I make it to false then my previous issue will not be fixed. I do not know what to do.
It would be really great if someone could help me.
As for your question, a NonUniqueObjectException is not because of setting lazy=true (or false). Can you post your mapping files and also the code where you are adding the child to the parent. Also please post the entire exception stacktrace which contains this error message
2007-07-27 12:32:49,992-http-7070-Processor23 (ERROR) LazyInitializationException.<init>(19) - failed to lazily initialize a collection of role: com.threeht.iriswi.biz.model.LineItem.asids - no session or session was closed org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.threeht.iriswi.biz.model.LineItem.asids - no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191) at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183) at org.hibernate.collection.AbstractPersistentCollection.write(AbstractPersistentCollection.java:61) at org.hibernate.collection.PersistentSet.add(PersistentSet.java:158)