[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3079) composite-id, sequence and merge call result in a NullPointerException

Cristian Dragoste (JIRA) noreply at atlassian.com
Fri Mar 28 03:23:33 EDT 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3079?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_29893 ] 

Cristian Dragoste commented on HHH-3079:
----------------------------------------

Hi,
I have the same problem and there are 2 weeks than I search for a solution.
I ha ve an entity A with a bag of B entitities. The bag is mapped with cascade="all,delete-orphan" inverse="true" (in fact I have tried all possible mappings).
Entity B has a composite id (with mapped="false" I mean has no a separate class for the composite id).
When I save or update or merge the entity A the id of thhis entity is not assigned to the B entities, so the cascading doesn't work.
When I use a separate class for the composite id, the cascading during update or merge works, but not for save.
I thought that is a bug of Hibernate and finally I found this post about the same problem.
I also search on the Hibernate forum but it seems that few people uses composite id.
Regards, Cristian.


> composite-id, sequence and merge call result in a NullPointerException
> ----------------------------------------------------------------------
>
>                 Key: HHH-3079
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3079
>             Project: Hibernate3
>          Issue Type: Bug
>    Affects Versions: 3.2.5
>         Environment: Oracle 10/XE
> Windows XP
> JDK 1.5.0
>            Reporter: Jean-Baptiste Lalanne
>         Attachments: oneup-hibernate-test.zip
>
>
> 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, see attached eclipse project sample that runs with an Oracle XE :
>    <!-- 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 ? :
> 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) 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list