-->
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: Best practices for lookup tables ?
PostPosted: Thu Apr 29, 2004 2:45 pm 
Beginner
Beginner

Joined: Wed Feb 25, 2004 10:58 am
Posts: 43
What r the best practices for simple lookup object, these tables will never change?

The thing is I have struts app, the web page has many drop down lists. When I submit the form the only thing available is the ids that were selected in the form. Prior to using hibernate I could easily just stick the id inside the object and subsequently send the object to the DAO layer (ex. Order had an order type id). Now using hibernate, would I have to do and extra select to get an object of order type and then plug this object into the order. This works fine, just wondering if this is the route that others are taking. My only concern was that this actual incurs an extra select that I was otherwise not doing before (The select being session.load to get the order type object). It also works fine if I just map the order type as normal property and set the id manually but as with almost every example I have seen the all foreign key references have been mapped with an object.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 29, 2004 2:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
The easiest thing would probably be using a read-only cache for just this class.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 29, 2004 3:31 pm 
Newbie

Joined: Wed Mar 24, 2004 11:13 am
Posts: 15
Location: Norcross, GA
I was in a similar position and am using Spring Application Context to handle the situation.

I get all data during the init method of one our servlet filters and populate List objects. These List objects are registered in the Spring Application Context at the same time. This makes it easy for us to use with Struts, our server side classes and test cases.

We do not need to update the listing at any point, so this works just fine. If you want to have a "mostly read" need, cache might be a better option.

Madhu


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 29, 2004 7:23 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
If you declare your OrderType object as a proxy, then when you do the following code:
Code:
Order order = new Order();
...
OrderType orderType = session.load(OrderType.class, orderTypeKey);
session.save(order);


Hibernate will issue the same SQL you would have issued yourself using direct JDBC.

When you call the load() method for the proxied object, Hibernate will just *assume* that a row exists in the appropriate table for the given OrderType key. It will then create a proxy OrderType instance (which looks just like a normal OrderType to you) and return that. After you hook that up to your Order and then call save(), Hibernate will see that the OrderType is a proxy and will only issue the SQL insert statement for the Order instance.

There's lots more info about proxies and reducing SQL statements and whatnot in the manual.

_________________
Cheers,
Shorn.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 29, 2004 9:41 pm 
Beginner
Beginner

Joined: Wed Feb 25, 2004 10:58 am
Posts: 43
just read the docs on what you have said ... exactly what I was looking for !!!!! Thanks a million ... infact this should help in several other situations for our project.

Serge


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.