-->
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.  [ 4 posts ] 
Author Message
 Post subject: composite key and single key mapping association
PostPosted: Tue Jun 19, 2007 11:03 am 
Newbie

Joined: Mon Jun 11, 2007 2:58 pm
Posts: 11
Hi,

If i have table say, "TABLEA" which has a primary key on one column, lets say on "COLM1" and has another table "TABLEB", which has a composite key of two columns (COLM1 and COLM2).

If i want to have an association with these tables, what should i put in the mapping xml file?

CLASSA represents TABLEA
CLASSB represents TABLEB.

CLASSA has a reference to CLASSB.
COMPOSITECLASS for composite key of TABLEB.


is the following mapping file is correct or does it needs any changes. Can any body help me with this issue.



Code:
<class name="CLASSA" table="TABLEA">
      <id name="keyID" column="COLM1">
           <generator class="assigned" />
        </id>
      ..... some other properties.
      <property />
                <property />
      .........
      <one-to-one name="classB" class="CLASSB"/>

   </class>


<class name="CLASSB" table="TABLEB">
   
      <composite-id name="compKey" class="COMPOSITECLASS">
         <key-property name="colm2" column="COLM2" type="integer"/>
         <key-many-to-one name="keyID" class="CLASSA" column="COLM1"/>
      </composite-id>      

                ..... some other properties.
      <property />
                <property />
               
   </class>


with this configuration i am getting mapping exception...

org.hibernate.MappingException: broken column mapping for: classB.id of: CLASSA


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 11:37 am 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
ClassB must have a many-to-one mapping to classA, with unique="true".

Thats the hibernate's way of completing one-to-one.

regards,
Jitendra


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 11:49 am 
Newbie

Joined: Mon Jun 11, 2007 2:58 pm
Posts: 11
but there is no "unique" attribute defined for <key-many-to-one...> mapping tag ind dtd file. I tried, it and it gives me exception, that "unique" attribute is not defined.


Top
 Profile  
 
 Post subject: Re:
PostPosted: Tue Jun 19, 2007 5:29 pm 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
Sorry i missed the one-to-one part. Try this:

Code:
<class name="ClassA" lazy="true" >

      <id name="id" column="id" type="long" unsaved-value="0">
          <generator class="increment"/>
      </id>
      
      <many-to-one name="classB" class="ClassB" unique="true">
         <column name="b_id" />
         <column name="a_id" />
      </many-to-one>
      
      <property name="note"/>


   </class>

   <class name="ClassB" >
      <composite-id class="ClassC" name="classC" >
         <key-property name="id" type="long"  ></key-property>
         <key-many-to-one name="classA" column="a_id" ></key-many-to-one>
      </composite-id>
      
      <property name="name"></property>
      
   </class>


*Please do rate if this helps*

Regards,
Jitendra


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.