Criteria API: Fetch of a list returns repeated main entity

后端 未结 2 698
醉话见心
醉话见心 2020-12-30 10:40

I have the following Entities; Ticket contains a set of 0,N WorkOrder:

@Entity
public class Ticket {

  ...

  @OneToMany(mappedBy=\"ticket\", cascade = Casc         


        
2条回答
  •  甜味超标
    2020-12-30 11:28

    Have you tried calling distinct(true) on the CriteriaQuery?

    The JPA 2 specification, page 161, says:

    The DISTINCT keyword is used to specify that duplicate values must be eliminated from the query result.

    If DISTINCT is not specified, duplicate values are not eliminated.

    The javadoc also says:

    Specify whether duplicate query results will be eliminated.A true value will cause duplicates to be eliminated. A false value will cause duplicates to be retained. If distinct has not been specified, duplicate results must be retained.

    The reason why you don't need the distinct when the association is eagerly loaded is probably just that the association is not loaded using a fetch join, but using an additional query.

提交回复
热议问题