Large images and long descriptions need different SQL types from ordinary byte arrays and strings. JPA’s @Lob maps a byte[] property to a BLOB and a String property to a CLOB. section 6.3.1
@Entity
public class Item {
@Lob
private byte[] image;
@Lob
private String description;
}
See both mappings on an entity. With these Java property types, Hibernate still loads the values when it loads the entity; @Lob alone does not make them lazy. section 6.3.1
For deferred access, use java.sql.Blob or java.sql.Clob properties instead. They hold placeholders when the entity loads and can materialize or stream the value when accessed within the same transaction, without bytecode instrumentation. section 6.3.1
@Entity
public class Item {
@Lob
private java.sql.Blob imageBlob;
@Lob
private java.sql.Clob description;
}
Compare the JDBC LOB property types with the byte[] and String mapping above. section 6.3.1
