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: Help required in mapping lookup table values
PostPosted: Tue Mar 21, 2006 8:59 pm 
Beginner
Beginner

Joined: Sat Mar 04, 2006 1:07 am
Posts: 27
Hibernate version:
3.1

I've have a data model that has an Employee table which has several foreign keys to a lookup table containing the (string) values. I want to store in my Employee domain object these actual values, rather than the lookup ids.
I want to be able to edit and query the data, and need advice on the best solution for this, bearing in mind that I can have just the one lookup table. Also, the primary key of the lookup table is a sequence, and not the actual lookup value, which is another column.

For example, an Employee has an attribute of state (where they live) and the values for state live in the lookup table. I want to be able to call a method on Employee called setState("NSW") (I live in Australia) and have the integer primary key of the "NSW" entry in the lookup table stored in the employee table. I hope this makes sense.

Would a join element in the mapping of Employee, joining on the Lookup table, work for inserting, updating and querying? Or is there a better solution?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 11:46 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
join wouldn't be appropriate, because that correlates to the is-a relationship rather than the has-a that you're describing.

If the lookup tables rarely/never change, you can go with the IntValuedEnum solution (see http://www.hibernate.org/273.html, though that's for StringValuedEnumType.. you can infer the changes easily). Then your API would be calling setState(State.NSW). That's better than the type-unsafe "NSW", and still allows you to use the strings at a slightly higher level (by having your enum know about both the integer and string representations of each state).

If the lookup tables do change (take, for example, branch office name: you don't want the user to be able to type in any old string, but you want to be able to add company branches easily), then map the lookup table as an ordinary entity class.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 23, 2006 6:12 am 
Beginner
Beginner

Joined: Sat Mar 04, 2006 1:07 am
Posts: 27
Once again tenwit, you have given me a good practical solution
Thanks and regards
Alan
ps please look out for post about a related lookup issue soon


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.