I have an class with an hasMany on a Long:
class Test {
static hasMany = [longList:Long]
}
I want to filter on longList with Criteria:
Test.createCriteria().list{
'in'('longList',[Long.valueOf('1')])
}
I get an SQLException: No value specified for parameter 1.
The SQL looks like this:
select * from test this_ where this_.id in (?)
i tried things like:
createAlias('labours', 'l')
eq('l',Long.valueOf(filter.labourId)) )
or
eq('labours.value', Long.valueOf(filter.labourId))
But i can't get it working.
For a workaround i would make another domain Class:
class Test {
statis hasMany=[longList:TestLongList]
}
class TestLongList{
Long longListItem
static belongsto = [test:Test]
}
This should be working but i must always create an TestLongList Instance if I create an Test Object, so the code would turn from:
test.addToLongList(Long.valueOf('22'))
to
TestLongList tll = new TestLongList
tll.test= test
tll.longListitem = Long.valueOf('22')
tll.save()
test.addToLongList(tll)
Is there a way to stay with the Long-List without HQL?
You have to rewrite the criteria to look like this:
This boils down to the property name under which Hibernate stores collection (
elements
).