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 badges1 Answer
Reset to default 0In 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
版权声明:本文标题:java - SetResultTransformer being deprecate in Hibernate 6 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736283395a1926954.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论