-->
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: My last ORM Question (apologies, really)
PostPosted: Mon Nov 03, 2003 3:43 pm 
Regular
Regular

Joined: Mon Oct 20, 2003 3:14 am
Posts: 53
Location: Sterling, VA, USA
I suspect if someone can explain to me the best way of handling this example, my confusion about surrogate keys will be over.

I've been trying to avoid asking this question because of the "Read the FAQ" missives, which I've done, but I'm sure I've missed the clue somewhere. In any case, this will save me from asking more.

If nothing else, I suspect this situation will make for a *great* example for the docs if it doesn't exist already.

Three Tables

User (PK - Id)
Language (PK - LanguageCode)
UserData (PK- User.UserId, Language.LanguageCode)

I'd love to make a surrogate PK for UserData, but I don't see how to get the database to enforce integrity for me.

Say I declare a Unique Id field and make UserId and Language Code both many-to-one associations with the respective tables?

What stops me from accidentally creating two UserData records for the same user and Language? Even if I make those two fields FK'd, the database wont stop me from duplicating combinations if their both valid.

I'm sure I'm doing this wrong, but how???

_________________
"A statistician is a mathmetician, broken down by age and sex".


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 03, 2003 4:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Define a unique constraint with the "natural key"

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 03, 2003 4:15 pm 
Regular
Regular

Joined: Mon Oct 20, 2003 3:14 am
Posts: 53
Location: Sterling, VA, USA
Doh!

Thank you. I knew it was going to be obvious.

_________________
"A statistician is a mathmetician, broken down by age and sex".


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.