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