java - Hibernate 5.2后如何使用 `setResultTransformer`?

标签 java hibernate

我想用 query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)获取 List<Map> .但我有一个异常(exception):

java.lang.NoSuchMethodError: org.hibernate.query.Query.setResultTransformer(Lorg/hibernate/transform/ResultTransformer;)Lorg/hibernate/Query;

我找不到 org.hibernate.query.Query 的实现类. 方法setResultTransformerorg.hibernate.Query .

为什么不推荐使用 org.hibernate.Query?

最佳答案

The ResultTransformer comes with a legacy definition which is not following the Functional Interface syntax. Hence, we cannot use a lambda in this example. Hibernate 6.0 aims to overcome this issue, so that’s why the Hibernate ORM 5.2 ResultTransformer is deprecated. Nevertheless, an alternative will be provided, so the concept we are discussing in this article is going to stand still even in Hibernate 6.

https://vladmihalcea.com/why-you-should-use-the-hibernate-resulttransformer-to-customize-result-set-mappings/

关于java - Hibernate 5.2后如何使用 `setResultTransformer`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38240015/

相关文章:

java - 由于缓冲区大小较小导致 MappedByteBuffer OOM?

java - 我可以在我的独立应用程序中使用谷歌翻译API吗

java - 无法使用 Eclipse IDE 连接到 SQL SERVER

java.lang.OutOfMemoryError Java堆空间解决方案(Netbeans和Tomcat-Spring-Hibernate)

java - 如何使用 MySQL 和 Hibernate 设置 group_concat_max_len

java - 如何使用 Eclipse 连接到带有 Hibernate 的 MySql

java - 在文件和控制台中显示标准输出(使用 System.setOut(new PrintStream(new File ("output-file.txt"))

java - 阻止 iText 表格在新页面上拆分

java - Spring Data Jpa findOne 方法返回托管实体吗?

java - hibernate 或数据库 : Which is better place for foreign key constraints?