A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
RabbitMQ in Depth
this week in the
Object Relational Mapping
Optimizing fetching with Hibernate - How do I get my ID?
Joined: Aug 21, 2004
Sep 12, 2007 03:14:00
One topic of Hibernate is to minimize the database hits when working with Hibernate and a domain model (POJOs). Hence Hibernate uses proxies based on the Hibenate Mappings instead of the real entity.
Look the next example from the book
Persistence with Hibernate
Item item = (Item) session.load(Item.class, new Long(123)); User user = (User) session.load(User.class, new Long(1234)); Bid newBid = new Bid("99.99"); newBid.setItem(item); newBid.setBidder(user); session.save(newBid);
The only database hit (INSERT) is at the last line in above example when doing save.
But where do I get my ID's (123, 1234) from? Wouldn't it be through a another database hit (SELECT)
Aren't there other solutions for obtaining the IDs w/o touching the database? I mean at some point one had to insert Item(123) and Bid(1234).
[ September 12, 2007: Message edited by: Darya Akbari ]
SCJP, SCJD, SCWCD, SCBCD
I agree. Here's the link:
subject: Optimizing fetching with Hibernate - How do I get my ID?
Inverse Attribute : Serious Problem
No proxy with session.load() instead it does a database hit - Why?
CascadeType.PERSIST not working
Hibernate Collection Fetch problem with fixed length CHAR
Loading proxy without hitting database
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015