It's not a secret anymore!
The moose likes Object Relational Mapping and the fly likes Hibernate EJB3 + Remote Lazy Loading Best Practices Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate EJB3 + Remote Lazy Loading Best Practices" Watch "Hibernate EJB3 + Remote Lazy Loading Best Practices" New topic

Hibernate EJB3 + Remote Lazy Loading Best Practices

Marcus Hathaway
Ranch Hand

Joined: Jun 07, 2005
Posts: 89
Hi Ranchers,

For several reasons as indicated here:, lazy loading of remote objects is not possible with hibernate.

After much research, i have seen solutions people have come up with to solve this, such as I also notice other products such as TopLink offer their own strategy to handle this (e.g. using javaagent with toplink-essentials-agent.jar).

I just wondered if anybody has any experience of this issue and how you decided to handle?

For examples sake, lets assume we have an object Order which lazy loads a collection of OrderItems. On the client (remote) site, we do a call to get the order items when needed. Using ejb3/hibernate, saying order.getOrderItems() would thrown an exception on the client (and rightly so). So what's approaches should be considered to get the order items?

Along with the solution i copied in above, of course the order items could be loaded on the server side before being returned to the client. However, let's assume we DON'T want to do this and only want to access this collection on the rare instance the order items are required (for arguments sake...).

Any experiences or points to provoke my thoughts would be greatly appreciated.

Rodrigo Lopes
Ranch Hand

Joined: Feb 29, 2008
Posts: 119
In my experience I solved this by (using your Order-OrderItems example):
Keep the OrderItem lazy loaded; provide a method to the client that loads the OrderItems for an specific Order, and use this method instead of the getter in the Order class.

I didn't know this H3T.
I agree. Here's the link:
subject: Hibernate EJB3 + Remote Lazy Loading Best Practices
It's not a secret anymore!