liveBook · Manning

@Lob annotation

As explained in Java Persistence with Spring Data and Hibernate epub

The JPA @Lob annotation maps a persistent property to a database large object value such as a BLOB or CLOB.

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

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Explains mappings and loading behavior, then contrasts them with JDBC LOB properties; defers bytecode-instrumented lazy loading.
Examples
Shows entity properties for images and descriptions as byte[], String, Blob, and Clob.
What it assumes
Assumes familiarity with Java entity properties and SQL columns; defines BLOB and CLOB as binary and character large objects.
What you can do after
Apply it via JPA @Lob to choose BLOB or CLOB mappings and recognize when JDBC LOB properties better support deferred access.
How it connects
Connects JPA entity mapping to SQL BLOBs and CLOBs, JDBC LOB types, lazy loading, and transactions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Java Persistence with Spring Data and Hibernate epub. The section links point to the parts of the book it draws on.