javajpaormpersistenceeclipselink

How to lazy load an entity attribute using JPA


I have a JSF application with JPA and EclipseLink. There is an entity with several attributes including a Lob type to store large binary data.

I need to frequently search the entities and display them in a list. Only when the user wants to view that, the Large Binary data is needed.

Can I have a method to lazy load the binary data? Or do I have to take it out as another entity with one to one relationship?


Solution

  • Can be done easily. Use the following annotation.

    @Basic(fetch=FetchType.LAZY)