-->
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: Design pattern for this situation
PostPosted: Wed Apr 21, 2004 1:12 pm 
Newbie

Joined: Fri Mar 26, 2004 8:51 am
Posts: 6
Hello to all, I have begun to see Hibernate and I am with a situation that I cannot solve.
Let us suppose that I have a User class
Code:
public class User {
private Integer userID;
private String username;
private String password;
private Description userType;
private Description userStatus;
... constructor and access methods...
}

and the Description class
Code:
public class Description {
private Integer ID;
private String description;
... constructor and access methods...
}

For the attributes userType and userStatus would have to define a relation many-to-one to Description.
The problem is that depending that attribute, acceding Description class would have to mapear it to different tables, if the attribute is userType Description would have to mapear to TabUserType and if the attribute is userStatus would have to mapear to TabUserStatus.
They are possible to be made this type of mappings in Hibernate?
I am mistaken in the form in which I am trying to design my classes? Would have to make a subclass specific each attribute to be able to mapear to different tables?
Thanks beforehand for its time.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 21, 2004 6:57 pm 
Regular
Regular

Joined: Mon Nov 24, 2003 6:36 pm
Posts: 105
check out the docs on inheritance. Typically when you have a userType field, in my opinion, it calls for inheritance. Hibernate can easily handle creating different types based on a user field. However, if you are stuck with a particular data model, it may not do quite what you want. Hibernate only uses a "type" field in the db, when there is 1 table, but many subclasses from one table. This results in many nullable fields in the DB, which to me is undersirable. I prefer common fields in common table, extended fields for each subclass in "subclass" tables.

As far as user status, no problem, hibernate can grab that "lookup" from the other table, using <many to one> type of relation from your user to your UserType java class/table.

--James


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.