Hello,
I got problem during the migration process from HB 2 to 3.2.5.
We use Oracle as DB, problem happens when calling merge on a persistent entity A. This instance A has a relation (one-to-many) to another entity B, this instance is transient and has a generated id (from an oracle sequence), it has also a one-to-many relation to a third entity C. This last one has a composite id that includes a reverse one-to-many link to B.
Here comes mapping definition :
Code:
<!-- entity A -->
<class name="EventImpl" table="EV_EVENT">
<id column="EVT_ID" name="id" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">SEQ_EV_ID</param>
</generator>
</id>
</class>
<!-- entity B -->
<class name="ScheduleImpl" table="EV_SCHEDULE">
<!-- primary key -->
<id column="SCH_ID" name="id" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">SEQ_EV_ID</param>
</generator>
</id>
<property column="LAB_ID" name="labId" not-null="true" type="java.lang.Long"/>
<set name="scheduleDetails" cascade="all-delete-orphan" lazy="false" inverse="true">
<key column="SCH_ID"/>
<one-to-many class="ScheduleDetailImpl"/>
</set>
</class>
<!-- entity C -->
<class name="ScheduleDetailImpl" table="EV_SCHEDULE_DETAIL">
<!-- Cache directive -->
<cache usage="read-write" />
<!-- Composite primary key -->
<composite-id name="id" class="ScheduleDetailImplPK">
<key-many-to-one
class="com.cegedim.oneup.events.srv.domain.schedule.impl.ScheduleImpl"
name="schedule"
column="SCH_ID"
/>
<key-property
column="LINE_RNK"
name="lineRnk"
type="java.lang.Long"
/>
</composite-id>
</class>
When calling merge on A i got this stacktrace, sounds like a bad propagation of the generated B PK during cascading. If i call saveOrUpdate all works fine, the HB2 code was calling the saveOrUpdateCopy and it worked fine. Does anybody got the same issue ? :
Code:
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.type.AbstractType.getHashCode(AbstractType.java:112)
at org.hibernate.type.AbstractType.getHashCode(AbstractType.java:120)
at org.hibernate.type.EntityType.getHashCode(EntityType.java:279)
at org.hibernate.type.ComponentType.getHashCode(ComponentType.java:189)
at org.hibernate.engine.EntityKey.generateHashCode(EntityKey.java:104)
at org.hibernate.engine.EntityKey.<init>(EntityKey.java:48)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:100)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:687)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:669)
at org.hibernate.engine.CascadingAction$6.cascade(CascadingAction.java:245)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:296)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:456)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:194)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:123)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:687)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:669)
at org.hibernate.engine.CascadingAction$6.cascade(CascadingAction.java:245)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
at org.hibernate.event.def.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:407)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsPersistent(DefaultMergeEventListener.java:152)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:126)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)
at com.cegedim.oneup.events.srv.domain.Test.testMergeScheduleDetails(Test.java:67)
at com.cegedim.oneup.events.srv.domain.Test.run(Test.java:83)
at com.cegedim.oneup.events.srv.domain.Test.main(Test.java:126)
Code:
Code: