使用Query.getResultList()
返回重复数据时遇到问题。我也做了一些研究,发现我们需要setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
。它工作正常。
但是,在hibernate 5.2中不推荐使用这种方法,我们正在使用hibernate 5.2.8,那么有没有其他方法可以做到这一点?
更新1:我使用的是HQL。查询看起来像这样:select u from UserEntity u left join fetch u.profile p left join fetch p.roles r left join fetch r.roleFunction
使用typedquery而不是问题。在最新的hibernate中,类型化查询为getresultlist或getsingleresult提供了许多选项......