-->
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.  [ 6 posts ] 
Author Message
 Post subject: Mapping not to primary key
PostPosted: Mon Jan 12, 2004 5:34 am 
Regular
Regular

Joined: Thu Sep 04, 2003 10:43 am
Posts: 61
I have the following problem:
TABLE A
-Primary Key name PkId
-A field named hCod not unique
-A field name X
TABLE B
-Primary Key named PkId
-A "foreign key" name idA
-A field named Y

The situation is not the "standard", because there is not foreign key constraint from idA (B) to pkId (A), because in idA of B there is the value of hCod of A. The "join" is made in this way:
SELECT ...
FROM B left outer join A on B.idA = A.hCod
AND B.Y = A.X

Is this possibile with Hibernate? How can I map it?
My real situation is a little more complex (B.Y = A.X is the simplification from the real situation). The important thing is that A must have the primary key on PkId (because there are other relations with that field), so I cannot use hCod+Y as a primary key.

Any help is very appreciated
Thanks
Alessandro Rizzi


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 6:36 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Check the property-ref attribute feature

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 4:27 am 
Regular
Regular

Joined: Thu Sep 04, 2003 10:43 am
Posts: 61
emmanuel wrote:
Check the property-ref attribute feature


Alredy tried, but it raise an error because hCod is not unique and when Hibernate tries to load a record by hCod, he finds more than once, so it raise an error.
Alessandro


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 6:51 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Consider not mapping that. Use an HQL query to retrieve appropriate data.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 7:12 am 
Regular
Regular

Joined: Thu Sep 04, 2003 10:43 am
Posts: 61
emmanuel wrote:
Consider not mapping that. Use an HQL query to retrieve appropriate data.


How can I make that HQL witout mapping?
Is possible to write the outer join statement without mapping? If yes how?
Alessandro


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 06, 2004 1:01 pm 
Newbie

Joined: Thu Jan 08, 2004 6:20 pm
Posts: 2
I have a similar problem (linking to a column that is not the primary key), using property-ref fixed all the join-conditions. However, the last condition in the select uses the value of the wrong field:

select ... from po_item_ordered poitemorde0_ left outer join po_item poitem1_ on poitemorde0_.item_id=poitem1_.item_id where poitemorde0_.po_id=1147

The last condition (po_id=1147) is checknig the right field, but against the wrong value:

I have a 1-many relation between po and po_item_ordered.
po has a field po_id (which is 'po3232' in my case) and a field db_id which is the primary key. I want to compare po_item_ordered.po_id against po.po_id, so the query should rather end like this:

po_id='po3232'

How do I do that?


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