我的Grails應用急切裝載查詢具有下列域對象與GORM /休眠
class ProductType {
String name
static hasMany = [attributes: Attribute]
}
class Attribute {
String name
static belongsTo = [productType: ProductType]
}
我DB具有7個ProductType
S和每個那些具有3 Attribute
秒。如果我執行查詢:
def results = ProductType.withCriteria {
fetchMode("attributes", org.hibernate.FetchMode.EAGER)
}
我期望返回的ProductType
7個實例,但事實上我得到21(7×3)。我明白,如果我執行等效的SQL查詢以上,結果集將有21行
prod1 | attr1
prod1 | attr2
prod1 | attr3
..... | .....
..... | .....
prod7 | attr1
prod7 | attr2
prod7 | attr3
-------------
Total 21
但我認爲,當我通過休眠/格姆獲取這些結果,我應該更喜歡得到的東西:
prod1 | attr1, attr2, attr3
..... | ...................
..... | ...................
prod7 | attr1, attr2, attr3
---------------------------
Total 7
順便說一句,如果我刪除從上面的查詢渴望加載,我得到7個ProductType
S作爲預期。我錯過了什麼?
我已經注意到了這個自己,但那是我回來使用時Grails 1.0.4,你能指定你正在使用的Grails的版本嗎? – billjamesdev 2009-09-21 01:48:32
我正在使用版本1.1.1 – 2009-09-21 20:33:46