Is it valid for Hibernate list() to return duplicates?

后端 未结 4 705
-上瘾入骨i
-上瘾入骨i 2020-12-09 08:35

Is anyone aware of the validity of Hibernate\'s Criteria.list() and Query.list() methods returning multiple occurrences of the same entity?

4条回答
  •  天涯浪人
    2020-12-09 08:46

    I also started noticing this behavior in my Java API as it started to grow. Glad there is an easy way to prevent it. Out of practice I've started out appending:

    .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
    

    To all of my criteria that return a list. For example:

    List paymentTypeAccounts = criteria()
      .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
      .list();
    

提交回复
热议问题