hibernate - Gorm returned value type -
i have object foo hasmany association bar object
class foo { string value static hasmany = [ bars: bar ] } class bar { string value }
when try follwing
def foo = foo.find("from foo f f.value=:value",[value:value])
the type of returned value foo foo, while when this
def foo = foo.find("from foo f left join f.bars b b.value=:value",[value:value])
the type object
can explain me why ?
thx, ken.
because second query selects properties of not foo
bar
. if println foo
, output second foo
this:
[foo : 3, bar : 2]
if add loggingsql = true
datasource
definition, hibernate output actual sql it's using stdout - like:
select foo0_.id id0_0_, bar2_.id id2_1_, foo0_.version version0_0_, foo0_.value value0_0_, bar2_.version version2_1_, bar2_.value value2_1_ foo foo0_ left outer join foo_bar bars1_ on foo0_.id=bars1_.foo_bars_id left outer join bar bar2_ on bars1_.bar_id=bar2_.id bar2_.value=?
ok. how avoid returning bar
query? - don't have solution.
i'd vote using select clause hql, in practice of syntaxes produce error in gorm. may possible solve using hibernate criteria
, don't know how.
so, start, might want state:
def foobar = foo.find("from foo f left join f.bars b b.value=:value", [value:value]) def foo = foobar[0] assert foo instanceof foo
edit: note one-to-one associations "dotty" syntax can used, i.e.,
from foo foo foo.baz.value=:value
Comments
Post a Comment