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

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

KeyType

The new KeyType enum is a FindOption that allows find() and findMultiple() to perform a load based on natural id in addition to identifier.

@Entity
class Person {
	@Id
	Integer id;
	@NaturalId
	String name;
	...
}

// loads by id, implicitly
session.find( Person.class, 1 );

// loads by id, explicitly
session.find( Person.class, 1, KeyType.IDENTIFIER );

// loads by natural-id
session.find( Person.class, "Bilbo Baggins", KeyType.NATURAL );

// load by multiple natural-ids
session.findMultiple( Person.class,
        List.of( "Bilbo Baggins", "Gandolph the Grey" ),
        KeyType.NATURAL );

@NaturalIdClass

The new @NaturalIdClass annotation models a non-aggregated composite natural id for the purpose of loading. It acts very much like @IdClass does for identifier loading.

@Entity
@NaturalIdClass(PersonNameKey.class)
class Person {
	@Id
	Integer id;
	@NaturalId
	String firstName;
	@NaturalId
	String lastName;
    ...
}

class PersonNameKey {
	String firstName;
	String lastName;
	...
}

Given this model, we can load Person by natural id via:

session.find( Order.class,
        new PersonNameKey( "Bilbo", "Baggins" ),
        KeyType.NATURAL );

Tenant-specific credentials

The new interface TenantCredentialsMapper allows an application to supply tenant-specific credentials to use for connecting to the database. This feature may be used on its own or in conjunction with schema-based or discriminator-based multitenancy. It requires a JDBC DataSource which correctly implements the method getConnection(String,String).

Entities and embeddables with no default constructor

JPA requires that entity cand embeddable classes have a default constructor (a constructor with no parameters). The bytecode enhancer now automatically adds a default constructor to any @Entity, @MappedSuperclass, or @Embeddable class which does not come equipped with one.

AnnotationBasedUserType and UserTypeCreationContext

As an alternative to and eventual replacement for ParameterizedType, the new interface AnnotationBasedUserType offers a programming model for configurable custom types inspired by the success of AnnotationBasedGenerator.

Check constraints on List order columns

The schema export tooling now automatically generates check constraints on `@OrderColumn`s.