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.  [ 3 posts ] 
Author Message
 Post subject: Relationship: View from Table that references other than PK?
PostPosted: Fri May 05, 2006 8:55 pm 
Newbie

Joined: Fri May 05, 2006 4:41 pm
Posts: 3
Location: California
Can I have a relationship to a view from a table - but this relationship references a property and not the FK?

If so, can you please explain where and how I can go about making this possible in the mapping file?

For example:

1) Table #1 - Address (parent table in one-to-many with Employer)

ADDRESS_ID (primary key)
ADDRESS_LINE1
ADDRESS_LINE2

2) Table #2 - Employer (child table in one-to-many with Address)

EMPLOYER_ID (primary key)
ADDRESS_ID (reference column to ADDRESS table - NOT a foreign key)
EMPLOYER_NAME


3) View - ResultingEmployees (parent table in one-to-one with Employer and takes child's ADDRESS_ID as primary key/foreign key)

ADDRESS_ID (primary key/foreign key that references ADDRESS_ID in Employer table)
COLUMN1
COLUMN2



**When I try to run an inner join query on ADDRESS_ID, Hibernate tries to use the primary key but it assumes the ADDRESS_ID is the primary key of the Employer table.

So, the question is - can I create a one-to-one relationship between two tables where I use a column/property other than the primary key (on the table sending the FK) as the column the other table references a the foreign key?

I know this is a pretty obscure example but I couldnt find anything in both the manual or the book that points to how to do this?

Please let me know if you have any questions and I will expound.

Thanks in advance.
F Diaz


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 06, 2006 6:48 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
property-ref should help you -> Hibernate reference explains it.

Best Regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 7:43 pm 
Newbie

Joined: Fri May 05, 2006 4:41 pm
Posts: 3
Location: California
I have tried both "property-ref" and the "properties" tag but I wasnt able to get the inner join (below) to work either.

HQL

Code:
select emp.addressId
from Employer as emp
inner join
emp.resultingEmployees
where
emp.addressId = 0001


Resulting SQL

Code:
select employer.address_id
from employer
inner join
resulting_employees
on employer.employer_id = resulting_employees.address_id
where
employer.address_id = 0001


***It seems that hibernate keeps trying to do the inner join on the primary key for the employer table instead of 'address_id' (bold/italics above) as indicated in the property-ref/properties tag.

I could be doing something wrong but everything seemed to be compiling fine when I tried loading the modified files.

Thanks


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