我从多个表中获取一些记录。使用 Hibernate join fetch
查询。
但我收到重复的记录。如果我指定 setMaxResults
参数而不进行任何修改,则查询工作正常。我不知道查询出了什么问题。
表结构为products
到Quantity
(一对多)和products
到category
(多对一) )和产品
到品牌
(多对一)
我的查询如下所示:
from ProductVO p
join fetch p.productsWithQuantity pq
join fetch pq.store
join fetch p.category cat
join fetch p.brand brand
join fetch p.subCategorys subCategory
where pq.productId=p.productId
最佳答案
我认为这是因为产品和数量表之间的联接,因为数量表对于一个产品有多行。尝试使用 DISTINCT。
关于mysql - hibernate中的重复记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24266116/