I would like to intersect two lists of instances of a specific domain class using grails 1.3.7.
The problem is, that the instances of one list are created by javasisst so that the result of the intersection is always an empty list.
Here are my domains:
class User {
...
static hasMany = [foos : Foo]
...
}
class Foo {
...
static hasMany = [bars : Bar]
...
}
class Bar {
...
static hasMany = [localizedTitles : LocalizedTitle]
...
}
I get the list of all Bar
instances of the user like this:
def allBarsOfUser = userInstance.foos.bars.flatten()
And try to intersect with another list of Bar
instances:
def intersectedBars = bars.intersect(allBarsOfUser)
The problem is, that the type of elements of allBarsOfUser
ist Bar_$$_javassist_139
and the the type of the elememts of bars
is Bar
so that intersectedBars
is always []
.
I solved my problem by doing the following - but I don't like the solution:
def allBarsOfUser = userInstance.foos.bars.flatten().collect{Bar.get(it.id)}
What would be a better solution?
How could I cast Bar_$$_javassist_139
to Bar
so that intersect()
works fine?