开发者

findAllByPropertyInList results in wrong result, JOIN related or hibernate Distinct/paging problem?

I have some strange results of findAllByPropertyInList() and think this is a 开发者_JAVA百科bug in grails. See [1], the result is not what I expect it to be and what other queries say. Could it be that some kind of JOIN blows up the result, than max-property is executed and afterwards DISTINCT decreases the number of results again?

Or does this have to do with Hibernate not being able to use DISTINCT and pagination proerties in one query?

thx Sebastian

[1]

def criteria = Foo.createCriteria()
def results = criteria.listDistinct() {
 ...
}
results.id.unique().size()
==>34
results.topic.unique().size() // some of the topics are duplicate
==>25
def more = Foo.findAll([max:20, offset:0]).size()
==>20
def more = Foo.getAll(results.id).size()
==>34
def more = Foo.findAllByTopicInList(results.topic, [max:20, offset:0]).size()
==> 7  // expected 25
def more = Foo.findAllByIdInList(results.id, [max:20, offset:0]).size()
==> 7  // expected 34

class Foo {
  String topic
  SubCategory subCategory
  List<Article> articles
  WritingStyle writingStyle
  SortedSet<Keyword> keywords = []as SortedSet
  SortedSet<String> linkTexts = []as SortedSet
  ArticleType articleType = ArticleType.FreestyleArticle

  static belongsTo = [project: Project]
  static hasMany = [articles:Article, keywords: Keyword, linkTexts: String]

  static constraints = {
    topic(blank: false, size: 1..200)
    subCategory(nullable: false)
    writingStyle(nullable: true)
    articles nullable:true
  }

  static mapping = {
    writingStyle fetch: 'join'
    subCategory fetch: 'join'
    keywords cascade: 'all-delete-orphan'
    keywords fetch: 'join'
    linkTexts cascade: 'all-delete-orphan'
  }
}


If you switch the fetch mode to lazy, it will work. This is kind of "known" behaviour of "max" in combination with join/eager fetch mode. See http://jira.grails.org/browse/GRAILS-5469

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜