-->
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: Help understanding what this is called and how to do it
PostPosted: Mon Jun 07, 2004 2:17 pm 
Newbie

Joined: Wed Apr 21, 2004 12:45 am
Posts: 11
Sorry for the vague subject, I really don't know quite what I'm asking yet so I need some help figuring out what this relationship is and how to do it.

Summary:
I have 3 entities (User, UserStatus and UserType). The User is assigned a Status and Type (e.g. "Active User" and "Administrator"). My DB is highly normalized in that my User table contains a FK reference to the UserStatus table and the UserType table. I want to figure out a way to add a getter on my User hibernate object that will actually return me the correct record from the UserType or UserStatus table,


Detail:
User Hibernate Object (DB table is a mirror of this)
Code:
int id;
int statusID; (FK to UserStatus table)
int typeID; (FK to UserType table)
String firstName;
String lastName;
<all getter/setters>


UserStatus Hibernate Object (DB table is a mirror of this)
Code:
int id;
String name;
String description;
<all getter/setters>


UserType Hibernate Object (DB table is a mirror of this)
Code:
int id;
String name;
String description;
<all getter/setters>



So what I want to do is change my User Hibernate Object to look like this:
Code:
int id;
int statusID; (FK to UserStatus table)
int typeID; (FK to UserType table)
String firstName;
String lastName;
<all getter/setters>
+ UserStatus getUserStatus();
+ UserType getUserType();


and have the 2 methods that I added at the end there, key off of the statusID and typeID values to actually have Hibernate load and return the respective UserStatus and UserType instances from the DB.

Is this possible? What kind of relationship is this called? I thought it might be a component, but then in the manual it mentions that component's fields need to be in the same table as the parent class, and in this case they aren't and I don't want to make them.

Any help or direction on this would be great, I don't mind getting my hands dirty and whacky away at code, I just need to know what I"m dealing with or if this isn't possible.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 07, 2004 2:36 pm 
Newbie

Joined: Wed Apr 21, 2004 12:45 am
Posts: 11
Just to clarify, a User can only have one UserStatus and UserType assigned to them. While Users will be unique, UserStatuses and UserTypes will not... so you could imagine in a system define 2 user statuses like "Active" and "Inactive" and then 2 user types like "Administrator" and "Normal", then say you have 10 users and all 10 of them would have any combination of those two user statuses and types assigned to them... pretty straight forward I think.

If it matters, I'm using 2.1.4 with MySQL 4.0.20 on Linux.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 07, 2004 2:43 pm 
Newbie

Joined: Wed Apr 21, 2004 12:45 am
Posts: 11
Ahh hell, it looks like this is a one-to-one relationship... I just changed my hibernate file around and tried it and it worked.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 07, 2004 7:27 pm 
Newbie

Joined: Wed Apr 21, 2004 12:45 am
Posts: 11
Seems I jumped the gun, this DID NOT work... can anyone help me with this?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 08, 2004 1:33 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This appears to be just a plain old many-to-one association.


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.