-->
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.  [ 2 posts ] 
Author Message
 Post subject: alternate primary keys problem
PostPosted: Mon Apr 01, 2013 4:12 pm 
Newbie

Joined: Mon Apr 01, 2013 3:49 pm
Posts: 1
I am working with a legacy database that features old and new tables.

One of the new tables looks something like this:
Table: Unit
PK guid
key1
key2

Even though guid is the primary key, older tables in the database use (key1,key2) as a foreign key to the Unit table, since these combinations are known to be unique. On the other hand, new tables use 'guid' to identify each element.

Effectively, I have two alternate primary keys. One single, the other composite.

I'm stuck because if I try to make (guid,key1,key2) a primary key, neither old nor new tables will be able to reference it since they never have all three. If I try to make guid the primary key, then the older tables complain that the foreign key '(key1,key2)' is not a primary key of Unit. If I make (key1,key2) the primary key, then the newer tables will complain that the foreign key 'guid' is not a primary key of Unit.

Advice would be appreciated!

-mv


Top
 Profile  
 
 Post subject: Re: alternate primary keys problem
PostPosted: Thu Apr 04, 2013 4:25 am 
Newbie

Joined: Wed Mar 13, 2013 11:32 am
Posts: 16
As I understand you problem you have one physical join table which is actual two logical join tables?

You can divide the physical table into two using database views and mapping the relation from new to old tables through the views as join tables. That is if you database system allows inserts and updates on views.

E.g.

Code:
create v_unit_key1 as select guid, key1 from unit;


Code:
creaet v_unit_key2 as select guid, key2 from unit;


Then use @JoinTable on your object relations.


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