2011-08-23 71 views
1

我有findAllByPropertyInList()的一些奇怪的结果,并认为这是一个在grails中的错误 。参见[1],结果不是我期望的 和其他查询说的。 难道是某种JOIN吹起结果,比执行最大属性 ,然后DISTINCT再次减少结果数 ?findAllByPropertyInList结果错误,JOIN相关或hibernate区别/分页问题?

或者这是否与Hibernate不能在一个查询中使用DISTINCT和分页合并有关?

THX塞巴斯蒂安

[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' 
    } 
} 
+0

我期望最后两个结果为20,因为您设置了最大参数。如果没有最大值,我希望在这两种情况下都是34。 – user852518

+0

可能你在你的域模型中有关联。你可以给我们看Foo吗?我想你已经定义了那些渴望而不懒惰的人。这将导致每个关联有一个结果项目。 – Chris

+0

@ user852518是你的权利,但仍然有一些结果丢失 – skurt

回答