-->
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.  [ 6 posts ] 
Author Message
 Post subject: Fail to understand solution to lookup tables
PostPosted: Fri May 20, 2005 10:45 am 
Beginner
Beginner

Joined: Tue May 10, 2005 4:18 am
Posts: 29
Hello All
I am a Hibernate newbie, and now looking for solution to handle my lookup tables. I mean those tables with 2 columns for id and name, such as country (1, "USA").
I searched and encountered some solutions that describe the use of a class for the lookup table.

Now - I think it is a pure waste. I do not regard the "country" table as an entity, but merely a warehouse for holding the list of countries, and for normalization. I really have no use to a "Country" class..

Further more, in my object model, I would really like to see I.E. in my "Contact" class a field of country of type String. Because I am interested in the country name...

Because I am also building a GUI, and would like to allow my user to have a "select box" of countries, I would also have something like "getCountries()" in my "Contact" class, to return a map of ID's, and String objects - with the county names.

My question is - Is there a way do achieve that using Hibernate, and if not - why ?


Top
 Profile  
 
 Post subject: Re: Fail to understand solution to lookup tables
PostPosted: Fri May 20, 2005 10:56 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
eladm wrote:
Hello All
I am a Hibernate newbie, and now looking for solution to handle my lookup tables. I mean those tables with 2 columns for id and name, such as country (1, "USA").
I searched and encountered some solutions that describe the use of a class for the lookup table.

Now - I think it is a pure waste. I do not regard the "country" table as an entity, but merely a warehouse for holding the list of countries, and for normalization. I really have no use to a "Country" class..

Further more, in my object model, I would really like to see I.E. in my "Contact" class a field of country of type String. Because I am interested in the country name...

Because I am also building a GUI, and would like to allow my user to have a "select box" of countries, I would also have something like "getCountries()" in my "Contact" class, to return a map of ID's, and String objects - with the county names.

My question is - Is there a way do achieve that using Hibernate, and if not - why ?


What is your objection to having an Object that is a country ? Since it's reference data that probably won't be updated often you can aggressively cache these objects using the second-level cache.

If you want to maintain the relationship of id and name in a collection, don't you need an object ?


Top
 Profile  
 
 Post subject: Lookup Table
PostPosted: Fri May 20, 2005 11:06 am 
Newbie

Joined: Thu Feb 17, 2005 3:01 pm
Posts: 9
We are using a lookup table to store all kindsof lookup values like status, payment method types etc.

These values are preloaded into a collection during application start up, so there is not roundtrip to the database to get these values. In our case these are static values and do not change that often.

But for individual types we have a class which the application can use if needed.

Hbm File
<class
name="com.fox.residuals.model.system.lookup.Lookup"
table="RESD_LOOKUP_CODE"
>

<id
name="lookupCode"
type="java.lang.String"
column="Lookup_code"
length="200"
>
<generator class="assigned" />
</id>
<discriminator column="LOOKUP_TYPE" type="string" />

<property
name="creationDate"
type="java.sql.Timestamp"
column="CREATION_DATE"
length="7"
/>
<property
name="modifiedDate"
type="java.sql.Timestamp"
column="MODIFIED_DATE"
length="7"
/>
<property
name="activeFlag"
type="yes_no"
column="ACTIVE_FLAG"
length="2"
/>

<property
name="version"
type="integer"
column="version"
/>


<property
name="displayedValue"
type="java.lang.String"
column="DISPLAYED_VALUE"
length="200"
/>
<property
name="lookupDescription"
type="java.lang.String"
column="LOOKUP_DESCRIPTION"
length="200"

/>

<subclass name="com.fox.residuals.model.system.lookup.ScheduleType" discriminator-value="SCHEDULETYPE"
>
</subclass>

<subclass name="com.fox.residuals.model.system.lookup.UnionPayType" discriminator-value="UNIONPAYTYPE"
>

There are integrity constraints at the DB level. We feel this will also help the reporting system

Hope this helps


Top
 Profile  
 
 Post subject: Fail to understand solution to lookup tables
PostPosted: Fri May 20, 2005 11:29 am 
Beginner
Beginner

Joined: Tue May 10, 2005 4:18 am
Posts: 29
Quote:
What is your objection to having an Object that is a country ? Since it's reference data that probably won't be updated often you can aggressively cache these objects using the second-level cache.


My objection is that my object model has an extra class only for hibernate needs. I do not need it. And I hoped the O.R. mapping can allow me to have just the object model I need..

Quote:
If you want to maintain the relationship of id and name in a collection, don't you need an object ?


No, I just need a map, with a simple long as an ID, and a simple String for its value. This is true for most of my lookup tables.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 20, 2005 11:36 am 
Beginner
Beginner

Joined: Tue May 10, 2005 4:18 am
Posts: 29
Quote:
We are using a lookup table to store all kindsof lookup values like status, payment method types etc.

These values are preloaded into a collection during application start up, so there is not roundtrip to the database to get these values. In our case these are static values and do not change that often.


I am not sure I understand. So you do not have an object for each lookup ? Where is the collection stored ? Could you ellaborate ? maybe with an example ?

Quote:
But for individual types we have a class which the application can use if needed.


So this mean you have a DB schema with a 1 table with a "lookup_type" column right ?
My DB schema is diferent. I have some table, each one is for 1 lookup. I wouldnt want to change the DB schema, as it is currently perfect for my needs.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 1:44 pm 
Beginner
Beginner

Joined: Thu Dec 29, 2005 12:08 pm
Posts: 31
Location: Acton, MA
Hello, eladm; have you received a satisfactory reply to this issue? I am facing the exact same issue as you, and as you've experienced in this particular topic, there doesn't seem to be a best practice here. I am about to resort to wild improvising.

Anyhow, if you've heard differently, please post any answer you've received!

Best,
Laird


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.