mysql - hibernate中的重复记录

标签 mysql spring hibernate nhibernate-mapping

我从多个表中获取一些记录。使用 Hibernate join fetch 查询。 但我收到重复的记录。如果我指定 setMaxResults 参数而不进行任何修改,则查询工作正常。我不知道查询出了什么问题。

表结构为productsQuantity(一对多)和productscategory(多对一) )和产品品牌(多对一)

我的查询如下所示:

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/

相关文章:

spring - Sun JSTL taglib 声明失败,出现 "Can not find the tag library descriptor"

java - 返回 json 意外,在 Spring 中将 "links"拼写为 "_links"并且结构不同

java - 如何解决javax.persistence.EntityExistsException : a different object with the same identifier value was already associated with the session

Hibernate FetchMode.JOIN 与 FetchMode.SUBSELECT

php - 如何从联结表中检索值作为字符串?

php - 具有权限的网络文件服务器框架?

php - 使用 PHP 从 Yahoo Finance 将 csv 导入 MySQL

java - Spring 环境中的多个@ConfigurationProperties validator bean

java - Spring Data JPA 批处理中的 CannotCreateTransactionException

mysql - 通过pymysql多进程更新MYSQL一张表