-->
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: Nobody Knows: how to map many-to-one via link table...
PostPosted: Tue Dec 09, 2008 2:36 pm 
Newbie

Joined: Tue Dec 09, 2008 1:59 pm
Posts: 1
Problem: mapping many-to-one via link table
need a mapping file ( Child.hbm.xml ) which uses a link collection table (LINKER) to map setOther & getOther to retrieve a single value or null from the OTHER table.

Attempts:
Almost got it working by by creating "map" and modifying the class to return a List, however in the real world I have no control over the definition of the classes or tables.

Context:
1. using normalized table-per-subclass mapping strategy
2. The setter/getter works with a single object (Other) not a Collection
3. There is a link collection table that which defines the relations (LINKER).
4. Using hibernate mapping file per class

Code:
class Parent
{
   private String _id;
   public String getID() { return _id; }
   public void setID( String id ) { _id = id; }
}

class Child extends Parent
{
   private Other _other;

   public Other getOther() { return _other; }
   public void setOther( Other other ) { _other = other; }
}

class Other
{
   private String _id;
   public String getID() { return _id; }
   public void setID( String id ) { _id = id; }
}


Code:
table PARENT ( pid, ...)
table CHILD ( cid, ... )
table OTHER ( oid, ...)
table LINKER( cid, oid );


Parent.htm.xml
Code:
<hibernate-mapping package="example">
  <class name="Parent" table="PARENT">
    <id column="pid" name="ID" type="string" unsaved-value="null">
      <generator class="uuid.hex"/>
    </id>
  </class>
</hibernate-mapping>


Child.hbm.xml ** THIS IS WHERE I NEED HELP
Code:
<hibernate-mapping>
  <joined-subclass extends="Parent" name="Child" table="CHILD">
    <key column="cid"/>
    <bag  cascade="all" name="Other" table="LINKER">
      <key>
        <column name="cid" not-null="true"/>
      </key>
      <many-to-many class="Other">
        <column name="oid" not-null="true"/>
      </many-to-many>
    </bag>
   </joined-subclass>
</hibernate-mapping>


Other.htm.xml
Code:
<hibernate-mapping>
  <class name="Other" table="OTHER">
    <id column="oid" name="ID" type="string" unsaved-value="null">
      <generator class="uuid.hex"/>
    </id>
  </class>
</hibernate-mapping>


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.