This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Optimizing fetching with Hibernate - How do I get my ID? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "Optimizing fetching with Hibernate - How do I get my ID?" Watch "Optimizing fetching with Hibernate - How do I get my ID?" New topic
Author

Optimizing fetching with Hibernate - How do I get my ID?

Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hi,

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 Java Persistence with Hibernate p.565:


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).

Regards,
Darya
[ September 12, 2007: Message edited by: Darya Akbari ]

SCJP, SCJD, SCWCD, SCBCD
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Optimizing fetching with Hibernate - How do I get my ID?
 
Similar Threads
Loading proxy without hitting database
Inverse Attribute : Serious Problem
CascadeType.PERSIST not working
Hibernate Collection Fetch problem with fixed length CHAR
No proxy with session.load() instead it does a database hit - Why?