-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: composite-id, sequence and merge problem
PostPosted: Mon Jan 21, 2008 6:11 am 
Newbie

Joined: Fri Jan 18, 2008 12:34 pm
Posts: 9
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:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 22, 2008 4:49 am 
Newbie

Joined: Fri Jan 18, 2008 12:34 pm
Posts: 9
None else got this problem ? Seems very strange because the case must be very comon ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 07, 2008 10:31 am 
Newbie

Joined: Fri Jan 18, 2008 12:34 pm
Posts: 9
I have tested it with the 3.2.6ga with the same result.

Does nobody got the same problem ?


Top
 Profile  
 
 Post subject: Hibernate cascade with composite key problem
PostPosted: Fri Feb 08, 2008 2:50 pm 
Newbie

Joined: Fri Feb 08, 2008 2:41 pm
Posts: 18
I have the same isue using a mysql database:

<class table="orders" name="hakim.order.model.Order">
<id name="id" column="order_id">
<generator class="native"/>
</id>
<many-to-one column="supplier_id" class="hakim.model.Supplier" not-null="true" name="supplier"/>
<set inverse="true" cascade="all-delete-orphan" name="frames">
<key column="order_id"/>
<one-to-many class="hakim.order.model.OrderFrame"/>
</set>

</class>

<class table="order_frame" name="hakim.order.model.OrderFrame">
<composite-id name="id" class="hakim.order.model.id.OrderFrameID">
<key-many-to-one name="order" class="hakim.order.model.Order">
<column name="order_id" not-null="true"/>
</key-many-to-one>
<key-many-to-one name="frame" class="hakim.model.Frame">
<column name="frame_id" not-null="true"/>
</key-many-to-one>
</composite-id>
<property name="colorCode" column="color_code"/>
<property name="quantity"/>
</class>

Does any one has an answer to this? I use the saveOrUpdate. When removing the cascade everthing works as normal.

The error happens after the following sql:
/* insert hakim.order.model.Order */
/* get current state hakim.order.model.OrderFrame */


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 11, 2008 4:40 am 
Newbie

Joined: Fri Jan 18, 2008 12:34 pm
Posts: 9
I have opened an issue in JIRA (http://opensource.atlassian.com/project ... e/HHH-3079 ) which seems to have been taken into account by the development team.
So I don't think there is a workaround for this issue.

You can vote for it if you're interested about this issue.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 28, 2008 3:32 am 
Newbie

Joined: Thu Apr 26, 2007 9:42 am
Posts: 14
Hi,
I have the same problem and I added a comment on your post on Jira.
Regards, Cristian.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.