MyGrailsアプリには次のドメインオブジェクトがあります
class ProductType {
String name
static hasMany = [attributes: Attribute]
}
class Attribute {
String name
static belongsTo = [productType: ProductType]
}
私のDBには7ProductType
秒あり、それぞれに3Attribute
秒あります。クエリを実行すると:
def results = ProductType.withCriteria {
fetchMode("attributes", org.hibernate.FetchMode.EAGER)
}
7つのインスタンスProductType
が返されることを期待していますが、実際には21(7 x 3)を取得します。上記と同等のSQLクエリを実行すると、結果セットには21行になることを理解しています。
prod1 | attr1
prod1 | attr2
prod1 | attr3
..... | .....
..... | .....
prod7 | attr1
prod7 | attr2
prod7 | attr3
-------------
Total 21
しかし、Hibernate / GORMを介してこれらの結果を取得すると、次のようなものが得られるはずだと思いました。
prod1 | attr1, attr2, attr3
..... | ...................
..... | ...................
prod7 | attr1, attr2, attr3
---------------------------
Total 7
ちなみに、上記のクエリからeager-loadingを削除すると、ProductType
期待どおりに7秒が取得されます。私は何が欠けていますか?