Hi all,
I have 3 classes :
ConflictInfo
Conflict which has a List of ConflictInfo
Ncuser which has a List of ConflictInfo
The Mapping files are :
ConflictInfo
Code:
<class name="com.newcompany.business.ConflictInfo" table="ncuserconflict">
<id name="id" type="int" column="id">
<generator class="sequence">
<param name="sequence">seq_ncuserconflict</param>
</generator>
</id>
<many-to-one name="conflict" class="com.newcompany.business.Conflict" column="ref_conflict" not-null="true"/>
<many-to-one name="ncuser" class="com.newcompany.business.Ncuser" column="ref_ncuser" not-null="true"/>
<many-to-one name="part" class="com.newcompany.business.Part" column="ref_part"/>
<many-to-one name="conflictarg" class="com.newcompany.business.Conflictarg" column="ref_conflictarg"/>
</class>
</hibernate-mapping>
Ncuser Code:
...
<list name="conflictInfos" lazy="true" table="ncuserconflict" inverse="true" cascade="all">
<key column="ref_ncuser" foreign-key="ref_ncuser" />
<index column="ref_conflict"/>
<one-to-many class="com.newcompany.business.ConflictInfo"/>
</list>
...
ConflictCode:
<list name="conflictInfos" lazy="true" table="ncuserconflict" inverse="true" cascade="all">
<key column="ref_conflict" foreign-key="ref_conflict"/>
<index column="ref_ncuser"/>
<one-to-many class="com.newcompany.business.ConflictInfo"/>
</list>
Ok, now, when I want to delete a Ncuser or a Conflict, this works very good and delete also the persisted ConflictInfo.
But if I replace cascade="all" with cascade="all-delete-orphan" I have an error :
java.lang.NullPointerException
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2562)
at net.sf.hibernate.impl.SessionImpl.isSaved(SessionImpl.java:2599)
at net.sf.hibernate.collection.PersistentCollection.identityRemove(PersistentCollection.java:607)
at net.sf.hibernate.collection.PersistentCollection.identityRemoveAll(PersistentCollection.java:601)
at net.sf.hibernate.collection.List.getOrphans(List.java:43)
at net.sf.hibernate.impl.SessionImpl.getOrphans(SessionImpl.java:3195)
at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:411)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:312)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:361)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:341)
at net.sf.hibernate.impl.SessionImpl.doDelete(SessionImpl.java:1101)
at net.sf.hibernate.impl.SessionImpl.delete(SessionImpl.java:1044)
at net.sf.hibernate.engine.Cascades$1.cascade(Cascades.java:58)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:296)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:361)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:341)
at net.sf.hibernate.impl.SessionImpl.doDelete(SessionImpl.java:1121)
at net.sf.hibernate.impl.SessionImpl.delete(SessionImpl.java:1044)
at net.sf.hibernate.engine.Cascades$1.cascade(Cascades.java:58)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:296)
at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:404)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:312)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:361)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:341)
at net.sf.hibernate.impl.SessionImpl.doDelete(SessionImpl.java:1101)
at net.sf.hibernate.impl.SessionImpl.delete(SessionImpl.java:1044)
at com.newcompany.dao.UserHibernateDAO.deleteUser(UserHibernateDAO.java:220)
at Test.test(Test.java:107)
at Test.main(Test.java:117)
Exception in thread "main" Process terminated with exit code 1
I think, it's like that hibernate don't detect the same ConflictInfo refers COnflict and Ncuser. It's a "buckle" ?.
Did I make an error on my mapping ? This is possible to do that ? Or I should keep "cascade="all" and my application will explicitly delete the ConflictInfo when I remove a ConflictInfo from a List ?
Thank you
J