File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lazy Loading problems and solutions

 
Max Galushka
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a small question related to Lazy loading features:

Let's imagine that we have a separated database layer that performs some operations with database and contains the method with business logic that retrieves some object in transaction and returns it to client.

Let's imagine that client for this business logic database layer is simple Servlet web application that need to display on the page some details of the retrieved object.

If the fields need to be displayed for such object is marked for lazy-loading - we will get an error on the view (Servlet) layer as far as objects returned by business logic are detached.

How can we manage such typical situations on the view (Servlet) layer of the application, what JPA basic/typical techniques exist for working in similar situations?

Thank you in advance.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Typically picking the point in your application that a business transaction starts and ends and using some sort of interceptor logic to do whatever your JPA implementation requires is the way to go, e.g. Open Session in view in Hibernate.

NB: your " business logic database layer" sounds a little like a poorly designed application. Why would your data access layer also perform business logic?
 
James Sutherland
Ranch Hand
Posts: 553
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several solutions to handling LAZY relationship detachment.

See,
http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Serialization.2C_and_Detaching

Some JPA providers such as EclipseLink, allow LAZY relationships to be accessed after the EntityManager is closed or transaction ends. However if you serialize the objects, you still have the same issue.

Ensuring your data access code instantiates the required relationships by accessing them, or using join fetching may be your best solution.
 
Max Galushka
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that is very helpful.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic