-->
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.  [ 2 posts ] 
Author Message
 Post subject: One-to-many with different primary/foreign key column names
PostPosted: Wed Feb 01, 2006 7:06 am 
Newbie

Joined: Mon Jan 16, 2006 1:25 am
Posts: 2
Hello

I have some problem in implementing one-to-many relationship.

I got a master table STYLE with STYLE_ID as primary key which maps to detail table ATTACHMENT 's column ID. ATTACHMENT table has composite key ID, ATTACHMENT_ID. Thus one style has many atttachments and distinguished by ATTACHMENT_ID for same ID or STYLE_ID of STYLE table.

When I try to fire query for retrieving attachments, it gives me error :
invalid identifier ATTACHMENT.STYLE_ID as there is no column as STYLE_ID in ATTACHEMNT table. Hibernate tries to search column same as primary key column in the "one" (here STYLLE) table in the "many" table(here ATTACHMENT). The equal columns involved in my case having different names, hence the problem.

Two classes are as follows.

<class name="Style" table="STYLE">
<id name="styleId" unsaved-value="0" >
<column name="STYLE_ID" sql-type="int(10)" not-
null="true"/>
<generator class="increment"/>
</id>
<set name="attachments" >
<key column="STYLE_ID" />
<one-to-many class="Attachment" />
</set>
</class>

<class name="Attachment" table="ATTACHMENT">
<composite-id>
<key-property name="styleId" column="ID"/>
<key-property name="attachmentId"
column="ATTACHMENT_ID" />
</composite-id>
</class>

Your help requested.

Girish Varde


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 9:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Code:
<set name="attachments" >
    <key column="ID" />
    <one-to-many class="Attachment" />
</set>


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