Search code examples
jpadb2jpqlopenjpa

OpenJPA1.2 - lazy load a BLOB


I have a very simple JPA entity. It features some simple metadata fields, and ID and a large ~500kB-10MB payload String.

@Entity
public class MyEntity{
  @Id
  @GenerateValue(Strategy=GenerationType.IDENTITY)
  private long myEntityId;

  private String metaData1; 
  ..
  private String metaDataN;

  @Lob
  private String payload; // large.

}

Most of the time, I am not intersseted in loading in the payload, but simply query the metadata fields. Is there a way to load the payload lazy without creating a specific Entity that wrapps the payload and have a lazy load one-to-one relation with that one from my main entity?

The whole thing is implemented using OpenJPA 1.2 and a DB2 backing database.


Solution

  • @Lob
    @Basic(fetch=FetchType.LAZY)
    private String payload;