-->
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: Using hibernate to instantiate a lookup table
PostPosted: Thu Mar 11, 2004 12:25 pm 
Beginner
Beginner

Joined: Thu Mar 04, 2004 11:51 am
Posts: 34
I want to build an in-memory lookup table of data from the database. This
data should simply be a set of elements each of which maps to a single column of a row of the table.

This set is not a part of any other persistent object. It is read-only. It will be read from the database but never written to. Its purpose in life is to sit in memory and used to validate a bunch of other data that does not come from the database. If this data contains a code that is in this table it is valid, if not, it isn't.

Is there a simple hibernate mapping that will build this object?

I have come up thus far with this mapping:

<class name="com.fubar.LocationLookupTable"
table="location"
mutable="false">

<id type="integer" unsaved-value="null">
<generator class="native"/>
</id>
<set name="codes" table="location" sort="unsorted">
<key column="location_code"/>
<element column="location_code" type="string"/>
</set>

</class>

My questions are these:
1. table is a required attribute of class but location does not really apply
here. The table is really an attribute of the set mapping.
2. id is completely inappropriate here but required.
3. the key element is the set is also required but not wanted. Can the key be the same as the element? Remember, this table is not part of some other object.

Of course I could write this by hand, but I want to know if there is a mapping construct that will build it without that.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 6:39 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You cannot have a set wo a parent entity, it's a bit of a non sense since set is here to implement a relation (ie between 2 objects)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 11:03 am 
Beginner
Beginner

Joined: Thu Mar 04, 2004 11:51 am
Posts: 34
It may not be supported by your model, but please don't call it nonsense. There is no reason a set cannot live apart from any relation to a persistent object. There is a use for it. If you want to clean up data that, for whatever reason, does not live in a database, you may want to pull up a collection of data from the database into a temporary in-memory table to aid in the validation process. You could query the database on each row of data you were cleaning, but that would be extremely non-performant.

It was easy enough to implement a solution in hibernate, without the aid of a hibernate mapping of the collection. However, although this may not be a high-frequency use case, it is a valid one, and one that it would be nice if Hibernate would think about a little more than your flip dismissal.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 3:01 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
A Set living wo parent is just call a query result actually :)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 3:04 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
stevecoh1 wrote:
it would be nice if Hibernate would think about a little more than your flip dismissal.

Please give me one good ORM tool supporting that.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 3:06 pm 
Beginner
Beginner

Joined: Thu Mar 04, 2004 11:51 am
Posts: 34
You're right of course, and that's how I implemented it. It wasn't hard, but I did have to hand-fill the Set I was storing the data in. Being able to achieve that from a hibernate mapping file instead of by code feels like a natural extension of the hibernate model, but it certainly isn't a necessity.


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.