-->
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: How do I map a join of 3 tables?
PostPosted: Tue Jul 08, 2008 10:12 am 
Newbie

Joined: Tue Jul 08, 2008 9:56 am
Posts: 3
I'm using Hibernate version 3.2
I have a database with 3 tables: A, B and A_B
Now I need to execute this query:

select from A, B, A_B, where A.id=A_B.id and B.cf=A_B.cf

I've created a class with all the fields, but don't know how to map the class.
I've tried this

<hibernate-mapping>
<class name="it.studio.model.ProgImpModel" table="Allocazione">
<composite-id>
<key-property name="aid" column="id"></key-property>
<key-property name="acf" column="cf"></key-property>
</composite-id>

<join table="Progetto" inverse="true">
<key column="id"></key>
<property name="pnome" column="nome"></property>
<property name="capo"></property>
<property name="descrizione"></property>
</join>
<join table="Impiegato">
<key column="cf" foreign-key="cf"></key>
<property name="inome" column="nome"></property>
<property name="cognome"></property>
<property name="ruolo"></property>
</join>
</class>

</hibernate-mapping>

but I got an error, saying that the number of fields for the key must be the same...

If I join only two table the mapping works:

<hibernate-mapping>
<class name="it.studio.model.AllProgModel" table="Allocazione">
<id name="aid" column="id"></id>
<property name="cf"></property>

<join table="Progetto" inverse="true">
<key column="id"></key>
<property name="nome"></property>
<property name="capo"></property>
<property name="descrizione"></property>
</join>
</class>
</hibernate-mapping>

'cause I declare only the desired field as key.

But in the first case, I need a key for table A and another for table B, and I cannot declare two <id>.


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.