-->
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.  [ 5 posts ] 
Author Message
 Post subject: Foreign IS the primary key
PostPosted: Wed Mar 03, 2010 8:46 pm 
Newbie

Joined: Wed Mar 03, 2010 8:36 pm
Posts: 3
Hey folks,

I'm relatively new to Hibernate and I must say, so far, it's been great!

I've been going through the tutorials and documentation trying to get my feet wet and have had relatively little problems, but one in-particular has been giving me some trouble.

Rest assured I've googled the shit out of this as well as a couple of search attempts on these forums (before I even created this account) but have yet to find an answer.

From a purely database perspective, I want two tables as follows:

Table A:
--------------------------------------------
| id | unique_field | some_other_fields | . . . |
--------------------------------------------


Table B:
-----------------------------------------------
| foreign_id | some_tableB_specific_fields | . . . |
-----------------------------------------------

It's pretty simple. All I need is for Table B's primary key to be a foreign key pointing to Table A's "unique_field". I know this is possible in non-ORM systems because I've done it before. One of the main reasons I'd like to start using hibernate as a main mode of database access is due it's convenience and simplicity, plus it slashes hours of tedious database development required to produce complex systems. I really do feel as though it's an incredible achievement for DB developers. It gets us back to the runtime code-object world instead of mucking around with DB stuff all the time.

I think I'm just missing something obvious here. I would be a bit worried if something as simple as a foreign-primary key was not able to be handled by such a robust ORM.

Is there any way (via annotations or mappings) to make this happen?

Thanks in advance for any advice/suggestions.


Top
 Profile  
 
 Post subject: Re: Foreign IS the primary key
PostPosted: Thu Mar 04, 2010 3:30 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
https://forum.hibernate.org/viewtopic.php?f=1&t=996354&hilit=foreign+key+to+not+primary+key


Top
 Profile  
 
 Post subject: Re: Foreign IS the primary key
PostPosted: Thu Mar 04, 2010 5:17 pm 
Newbie

Joined: Wed Mar 03, 2010 8:36 pm
Posts: 3
Wow, thanks for clearly not thoroughly reading the thread topic or the content of my post.

I've been able to easily construct a situation similar to that poster, however this is the extent of my abilities.

Also, let me remind that the PRIMARY key of Table B must ALSO be the FOREIGN key referencing Table A's "unique field".

If you have any useful information, please post it, but I'd rather you not waste my time with arrogant no-comment replies to a linked thread that is irrelevant.


Top
 Profile  
 
 Post subject: Re: Foreign IS the primary key
PostPosted: Fri Mar 05, 2010 3:20 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Sorry for wasting your time, it seemed to me, that the linked thread contained informations which may helping you.
I was absolutely not intended to be arrogant.
Mapping foreign keys to not primary keys is very unusual and therefore informations in regard to this topic are rare.
Also I did find nothing about in the book 'Java Persistence with Hibernate'.


Top
 Profile  
 
 Post subject: Re: Foreign IS the primary key
PostPosted: Wed Mar 17, 2010 10:36 am 
Newbie

Joined: Wed Mar 03, 2010 8:36 pm
Posts: 3
I apologize for being so quick to judge, then. I've just had too many bad experiences with "experienced" forum posters who don't actually care to post any useful information.

I eventually found a fix for my problem. Not exactly what I intended, but I suppose that's simply a product of my inexperience with Hibernate. Still getting used to the switch from retrieving things from a database using sql and then cross-filling as opposed to automated population.

If you -do- know of a way to add a foreign key constraint to a primary key of an object, that information would still be much appreciated.


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