admin管理员组

文章数量:1122826

I am just upgrade my project to spring boot 3 and also hibernate 6.

Then I just realize this function seem not support anymore.

Seem like the setResultTransformer is being deprecated in Hibernate 6 and also the LocalDateTimeType package are not able to being import anymore.

Does anyone know how below code to change so it can be resolve under hibernate 6 or any studying material regarding this issue?

I am just upgrade my project to spring boot 3 and also hibernate 6.

Then I just realize this function seem not support anymore.

Seem like the setResultTransformer is being deprecated in Hibernate 6 and also the LocalDateTimeType package are not able to being import anymore.

Does anyone know how below code to change so it can be resolve under hibernate 6 or any studying material regarding this issue?

Share Improve this question asked yesterday Bing HaoBing Hao 177 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

In Hibernate 6, setResultTransformer has been replaced with TupleTransformer and ResultListTransformer. Instead of using:

.setResultTransformer(Transformers.aliasToBean(CompanyRecommendation.class))

You should now use:

.setTupleTransformer((tuple, aliases) -> {
    CompanyRecommendation dto = new CompanyRecommendation();
    // Map the properties
    return dto;
})

More info about this topic here: https://vladmihalcea.com/hibernate-tupletransformer

For the LocalDateTime fields in your query, you can use this instead: https://docs.jboss.org/hibernate/orm/6.0/javadocs/org/hibernate/type/StandardBasicTypes.html

Query query = entityManager
    .createNativeQuery(sql.toString())
    .unwrap(NativeQuery.class)
    // other fields ....
    .addScalar("effectiveFrom", StandardBasicTypes.LOCAL_DATETIME)
    .setTupleTransformer((tuple, aliases) -> {
        // Transform logic here
        return new CompanyRecommendation();
    });

Check this post: https://thorben-janssen.com/hibernate-6-offsetdatetime-and-zoneddatetime

本文标签: javaSetResultTransformer being deprecate in Hibernate 6Stack Overflow