-->
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: Efficient way of setting foreign keys without lookups?
PostPosted: Mon Aug 13, 2007 10:18 am 
Newbie

Joined: Mon Aug 13, 2007 10:00 am
Posts: 8
I'm currently porting an application from JDBC to Hibernate and have some concerns about the performance overhead and would like to ask more experienced Hibernate users what the best solution is for my problem.

Rather than explaining the application in detail, I've summarised the general issue I have concerns with.

Imagine a typical web site selling products ...

The customer is presented with a web page listing products for sale. The customer clicks the "Buy Now" button next to a product. This sends the
"product id" as a parameter to the web app.

The legacy JDBC code would simply perform an insert into an "order_item" table (the web app is mostly stateless). Because the product_id is a parameter there is no need to lookup the product.

With hibernate, I find myself performing a query to get a Product object and then call orderItem.setProduct(product). This obviously introduces an additional database query that wasn't need before.

Is this "just the way it is" when using Hibernate or are there other techniques for setting foreign-keys without needing to perform the lookup to retrieve the object being referenced?

Thanks,

Andy Grove.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 13, 2007 11:55 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Quote:
With hibernate, I find myself performing a query to get a Product object and then call orderItem.setProduct(product). This obviously introduces an additional database query that wasn't need before.


There is no query if you use session.load(product) because a proxy will be used.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 13, 2007 12:39 pm 
Newbie

Joined: Mon Aug 13, 2007 10:00 am
Posts: 8
Christian,

Thanks. That's just what I needed. I also realize now that the get() calls were loading the objects from the cache in any case so I was needlessly worrying about the impact of this design difference between JDBC and Hibernate.

_________________
Thanks,

Andy Grove


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.