-->
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.  [ 7 posts ] 
Author Message
 Post subject: Heeeeeelp
PostPosted: Tue May 22, 2007 8:15 am 
Beginner
Beginner

Joined: Fri Feb 10, 2006 8:33 am
Posts: 32
Table A{
id INT;
type INT;
AB_id INT;}


B extends A

Table B{
id INT;
Name String;}

C extends A

TABLE C{
id INT;
description String;}
Code:
<class name="A" table="A"  discriminator-value="0">
.
.
<discriminator>
      <column name="т..е" sql-type="INTEGER"/>
    </discriminator>
.
.
<subclass B discriminator-value="1">
<join table="B">
  <key>.....</key>
  <propertie name="name" column="name"/>
</joint>
</subclass>

<subclass C discriminator-value="2">
<join table="C">
  <key>.....</key>
  <propertie name="description " column="description"/>
</joint>
</subclass>
</class>



As you see, this is simple inheritance but i can't find how to say that join between A and B, A and C must be via column A.ab_id = B.id and A.ab_id=C.id.

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 22, 2007 8:30 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi


Quote:
<class name="A" table="A" discriminator-value="0">
.
.
<discriminator>
<column name="т..е" sql-type="INTEGER"/>
</discriminator>
.
.
<subclass B discriminator-value="1">
<join table="B">
<key column="id" property-ref="ab_id"
/>
<propertie name="name" column="name"/>
</joint>
</subclass>

<subclass C discriminator-value="2">
<join table="C">
<key column="id" property-ref="ac_id"/>
<propertie name="description " column="description"/>
</joint>
</subclass>
</class>



Amila

(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 22, 2007 8:37 am 
Beginner
Beginner

Joined: Fri Feb 10, 2006 8:33 am
Posts: 32
No. This is not a decision.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 22, 2007 8:45 am 
Beginner
Beginner

Joined: Fri Feb 10, 2006 8:33 am
Posts: 32
My be this is impossible with Hibernate!!!!????


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 22, 2007 8:58 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

why not

Code:
<class>
<subclass B discriminator-value="1">
<join table="B">
<key column="id" property-ref="[color=red]ab_id[/color]"
/>
<propertie name="name" column="name"/>
</joint>
</subclass>


<propertie name="[color=red]ab_id[/color]" column="ab_id"/>
</class>



Amila


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 22, 2007 9:11 am 
Beginner
Beginner

Joined: Fri Feb 10, 2006 8:33 am
Posts: 32
Hi
I don't know why.
My be this is bug.
But when i have only

..
join table="B">
<key column="id"/>
<propertie name="name" column="name"/>
</joint>
..
generated SQL is some like:

..
FROM
A somename0_
LEFT OUTER JOIN
B somename0_1_
ON
somename0_.id= somename0_1_.id
..

when :
..
join table="B">
<key column="id" property-ref="ab_id"/>
<propertie name="name" column="name"/>
</joint>
..

generated SQL is absolutely identical

..
FROM
A somename0_
LEFT OUTER JOIN
B somename0_1_
ON
somename0_.id= somename0_1_.id
..

THE property-ref="ab_id" don't change nothing.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 22, 2007 9:45 am 
Beginner
Beginner

Joined: Fri Feb 10, 2006 8:33 am
Posts: 32
The general question is:
How to join a table using a foreign key other than the primary key

This is a fundamental and essential feature of SQL.


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