-->
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: Joining a table one-to-one
PostPosted: Tue Jul 21, 2009 3:06 pm 
Newbie

Joined: Tue Jul 21, 2009 2:58 pm
Posts: 6
Hello,

I have the following problem. I have three tables.


A -------- C --------- B


A contains x amount of records
B contains y amount of records
C associates 1 record from A with B

I want to create a hibernate mapping that will make this clean and easy.

I have ClassA, ClassB, ClassC

I want it so a getter in ClassA returns ClassB via table C. I have achieved this with the following but it is not perfect

<set name="a" inverse="false" table="C">
<cache usage="read-write" region="StandardQueryCache" />
<key>
<column name="A_ID" precision="22" scale="0" not-null="true" />
</key>
<many-to-many entity-name="com.test.B">
<column name="B_ID" precision="22" scale="0" not-null="true" />
</many-to-many>
</set>

<set name="b" inverse="false" table="C">
<cache usage="read-write" region="StandardQueryCache" />
<key>
<column name="B_ID" precision="22" scale="0" not-null="true" />
</key>
<many-to-many entity-name="com.test.A">
<column name="A_ID" precision="22" scale="0" not-null="true" />
</many-to-many>
</set>

This works however since the relationship between A and B will ALWAYS be one-to-one, this is kind of a hack.

Any help on how to clean this up would be greatly appreciated.

Thanks,

Brad


Top
 Profile  
 
 Post subject: Re: Joining a table one-to-one
PostPosted: Tue Jul 21, 2009 3:07 pm 
Newbie

Joined: Tue Jul 21, 2009 2:58 pm
Posts: 6
Please note, the names of the tables are changed to simplify/shorten the question.

Thanks,

Brad


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.