This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Optimizing fetching with Hibernate - How do I get my ID?