Need To Know About Hibernate 6
Need To Know About Hibernate 6
Based on JPA 3
Hibernate 6.0 updates the supported JPA version to 3.0.
If you’re still using the old API, you need to reimplement it using JPA’s
Criteria API. I explained this in my Migrating from Hibernate’s to JPA’s
Criteria API article.
thorben-janssen.com
Hibernate 6
New default sequences
Starting with version 6, Hibernate uses a separate default sequence for
every entity class. It follows the naming pattern <table name>_SEQ.
If you want to keep using the old default naming strategy, you need to
configure the ID_DB_STRUCTURE_NAMING_STRATEGY property in
your persistence.xml file. If you set it to legacy, Hibernate will use the
same default strategy as in the Hibernate versions >= 5.3 but <6. And if
you set it to single, you get the same default strategy as in Hibernate
versions < 5.3.
<persistence>
<persistence-unit name="my-persistence-unit">
...
<properties>
<property name="hibernate.id.db_structure_naming_strategy"
value="standard" />
...
</properties>
</persistence-unit>
</persistence>
Incubating features
The new @Incubating annotation tells you that a new API or
configuration parameter might still change.
The Hibernate team wants to use it when they release a feature for which
they’re looking for further user feedback or if they’re releasing a subset of
a set of interconnected features. In that case, some of the missing
features might require additional changes on the already released APIs.
thorben-janssen.com
Hibernate 6
ResultTransformer replaced by TupleTransformer and
ResultListTransformer
Hibernate 6 split the ResultTransformer interface into the
TupleTransformer and the ResultListTransformer interfaces. These are
functional interfaces that separate the transformation of a single tuple
from the transformation of the list of transformed tuples.
PersonDTO person = (PersonDTO) session.createQuery(
"select id as personId, first_name as firstName, "
+ "last_name as lastName, city from Person p", Object[].class)
.setTupleTransformer((tuples, aliases) -> {
log.info("Transform tuple");
PersonDTO personDTO = new PersonDTO();
personDTO.setPersonId((int)tuples[0]);
personDTO.setFirstName((String)tuples[1]);
personDTO.setLastName((String)tuples[2]);
return personDTO;
}).getSingleResult();
...
}
thorben-janssen.com
Hibernate 6
To use it as an entity attribute and map it to a JSON document, you need
to annotate it with @Embedded and @JdbcTypeCode(SqlTypes.JSON)
and include a JSON mapping library in your classpath.
@Entity
public class MyEntity {
@Embedded
@JdbcTypeCode(SqlTypes.JSON)
private MyJson jsonProperty;
...
}
thorben-janssen.com
Hibernate 6
The EmbeddableInstantiator is a proprietary Hibernate interface that
tells Hibernate how to instantiate an embeddable object. This removes
JPA’s requirement of a no-argument constructor and enables you to
model an embeddable as a record.
thorben-janssen.com