-->
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.  [ 1 post ] 
Author Message
 Post subject: idbag of objects that have idbags, second set not persisted
PostPosted: Wed Mar 18, 2009 2:07 pm 
Newbie

Joined: Thu Feb 26, 2009 7:30 pm
Posts: 7
I have classes A, B and C (each with their own table). A has a many-to-many B kept in association table AB. Each of those has a many-to-many to C kept in association table AB_C. Because the AB relationship is related to more information that just which A is related to which B, it also must maintain relationships to C, I created an AB class that is also mapped to the AB table (based on section 6.3.2 in Hibernate in Action). The mappings and objects are as follows:

A mapping
Code:
<hibernate-mapping>
    <class name="A" table="A">
        ... some other properties, including an id, A_ID
        <idbag name="myBs" table="AB" cascade="save-update" lazy="false" fetch="join">
           <collection-id type="java.lang.Integer" column="AB_ID">
              <generator class="sequence">
                 <param name="sequence">MY_SEQ</param>
              </generator>
           </collection-id>
            <key column="A_ID" not-null="true"/>
            <composite-element class="AB">
               <parent name="myA"/>
               <many-to-one name="myB"
                         column="B_ID"
                         class="B"
                         not-null="true"
                         cascade="save-update"/>
            </composite-element>
        </idbag>
    </class>
</hibernate-mapping>


A Java Object
Code:
public class A
{
      private Integer A_ID;
      private List<AB> myBs;

      public addB(B b)
      {
            AB tempReltn = new AB(this, B);
            a2bRelationships.add(tempReltn);
      }
}


B mapping
Code:
<hibernate-mapping>
    <class name="B" table="B">
        ... some other properties, including an id, B_ID
    </class>
</hibernate-mapping>


B Java Object
Code:
public class B
{
      private Integer B_ID;
      ...other properties
}


AB mapping
Code:
<hibernate-mapping>
    <class name="AB" table="AB">
        ... some other properties, including an id, AB_ID
        ... no inverse relationship, is one needed?
        <idbag name="myCs" table="AB_C" cascade="save-update" lazy="false" fetch="join">
             <collection-id type="java.lang.Integer" column="ABC_ID">
              <generator class="sequence">
                 <param name="sequence">MY_SEQ</param>
              </generator>
            </collection-id>
            <key column="AB_ID" not-null="true"/>
            <composite-element class="ABC">
               <parent name="myAB"/>
               <many-to-one name="myC"
                         column="C_ID"
                         class="C"
                         not-null="true"
                         cascade="save-update"/>
            </composite-element>
        </idbag>       
    </class>
</hibernate-mapping>


AB Java Object
Code:
public class AB
{
      private Integer AB_ID;
      //parent in the mapping
      private A myA;
      //Composite element with many to one reltn
      private B myB;

      private List<ABC> myCs;

      public addC(C b)
      {
            ABC tempReltn = new ABC(this, C);
            ab2cRelationships.add(tempReltn);
      }
}


C Java Object
Code:
public class C
{
      private Integer C_ID;
      ...other properties
}


ABC stuff is mapped pretty much identically to the AB stuff, only using an AB as an object in the relationship.

When I debug this stuff, it seems as though all the objects are there. The A has the correct list of AB's which holds the correct B's and the AB's have the needed ABC objects with the correct C's. But when I save the A, the AB's and B's are persisted and the tables are updated correctly. However, the C's are not saved and therefore neither are the corresponding relationships. The sql to do so is never executed. I noticed during debug that the A's ArrayList of AB's is a PersistedIdentifierBag, but the AB's ArrayList of ABC's is not, its just an ArrayList.

Open to any suggestions, thanks!


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

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.