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.