-->
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: Need Help mapping Foreign Key. This should be easy
PostPosted: Sat Mar 07, 2009 12:24 am 
Beginner
Beginner

Joined: Sat Feb 07, 2009 4:08 pm
Posts: 22
Location: New York City
I have two tables that I want to map correctly. A user table, and a user_session table. The User_session table gets populated with one row per user when they log in, and then that row is deleted when they log off.

I was planning on linking the two tables by username (which is unique but not a primary key in either table) but I am confused if this is a real OneToOne relationship. All I originally wanted to do was somehow declare that the user_session.username column was a foreign key of user.username. I am all confused at this point. What is the correct way I should be mapping this?

Thanks


table User
Long id
String username
etc, etc,

table User_Session
long id
String username
String ServerID
Date updated
etc,etc,


Top
 Profile  
 
 Post subject: Re: Need Help mapping Foreign Key. This should be easy
PostPosted: Sun Mar 08, 2009 11:23 pm 
Newbie

Joined: Mon Mar 28, 2005 8:54 pm
Posts: 4
Location: Idaho
JohnRock wrote:
I have two tables that I want to map correctly. A user table, and a user_session table. The User_session table gets populated with one row per user when they log in, and then that row is deleted when they log off.

I was planning on linking the two tables by username (which is unique but not a primary key in either table) but I am confused if this is a real OneToOne relationship. All I originally wanted to do was somehow declare that the user_session.username column was a foreign key of user.username. I am all confused at this point. What is the correct way I should be mapping this?

Thanks


table User
Long id
String username
etc, etc,

table User_Session
long id
String username
String ServerID
Date updated
etc,etc,



Declare username unique in each table, then you will be guaranteed a one-to-one mapping and the set will only have one member.

Dave


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.