2011-08-23 44 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

回答