Describes the new features and capabilities added to Hibernate ORM in 7.2.

If migrating from earlier versions, be sure to also check out the Migration Guide for discussion of impactful changes.

@EmbeddedTable

The Jakarta Persistence compliant way to specify the table to which an embedded value maps is tedious, at best, requiring us of multiple @AttributeOverride and/or @AssociationOverride annotations -

@Entity
@Table(name="primary")
@SecondaryTable(name="secondary")
class Person {
	...

    @Embedded
    @AttributeOverride(name="street",
        column=@Column(table="secondary"))
    @AttributeOverride(name="city",
        column=@Column(table="secondary"))
    @AttributeOverride(name="state",
        column=@Column(table="secondary"))
    @AttributeOverride(name="zip",
        column=@Column(table="secondary"))
    Address address;
}

Hibernate now provides the EmbeddedTable annotation to help make this easier -

@Entity
@Table(name="primary")
@SecondaryTable(name="secondary")
class Person {
	...

    @Embedded
    @EmbeddedTable("secondary")
    Address address;
}

The annotation is only legal on top-level embedded. Placement on nested embedded values will be ignored.

Read-only replicas

This release features experimental support for accessing data held in read only replicas of the main database.

Introduction of FindMultipleOption

Previous versions of Hibernate supported loading multiple entities of a type via the Session#byMultipleIds method. 7.0 added Session#findMultiple methods which accepted FindOption configuration; but, for options specific to multiple-id loading, users still had to revert to Session#byMultipleIds. 7.2 covers this gap and introduces new FindMultipleOption configuration -

  • SessionCheckMode

  • OrderingMode

  • RemovalsMode

Session#byMultipleIds and MultiIdentifierLoadAccess have been deprecated.

Child StatelessSession

Creation of child StatelessSession is now supported, just as with child Session. This is a StatelessSession which shares "transactional context" with a parent Session or StatelessSession. Use Session#statelessWithOptions or StatelessSession#statelessWithOptions instead of #sessionWithOptions.

Session parent = ...;
StatelessSession child = parent
    .statelessWithOptions()
    .connection()
    ...
    .open();

Hibernate-Vector module enhancements

Support for binary, float16 and sparse vectors were added.

@Entity
public class MyEntity {
	@Id
	UUID id;
	@JdbcTypeCode(SqlTypes.VECTOR_BINARY)
	@Array(length = 24) // Refers to the bit count
	byte[] binaryVector;
	@JdbcTypeCode(SqlTypes.VECTOR_FLOAT16)
	@Array(length = 3)
	float[] float16Vector;
	@Array(length = 3)
	SparseFloatVector sparseFloat32Vector;
}

The Hibernate Vector module currently ships with 3 sparse vector types:

  • SparseByteVector

  • SparseFloatVector

  • SparseDoubleVector

In addition to accessing the sparse indices and values, they also implement the List interface to provide access as if it were a dense vector.

Also, support for vectors in the following databases was added:

Enhancements to SchemaManager

Two new methods were added to SchemaManager:

  • resynchronizeGenerators() force all sequences to catch up with data imported to their corresponding tables

  • truncateTable() truncates a single table and resets its corresponding primary key sequence

In addition, truncate() now automatically resets all primary key sequences and tables backing table generators.

Regular expression support in HQL

The operators like regexp and ilike regexp were added to HQL, allowing patterns to be written as regular expressions.