Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GORM where query on an embedded object

I have domain classes A and B as follows:

class A {
    String prop1
    String prop2
    B prop3

    static embedded = ['prop3']
}

class B {
    String prop4
    String prop5
}

When I want to query like this:

def q = A.where { prop3.prop4 == 'bla' }
def list = q.list()

I get the following exception:

Cannot get property 'javaClass' on null object. Stacktrace follows:

on the "def q = A.where ..." line.

Any clue what's the problem? I've checked this:

http://grails.1312388.n4.nabble.com/GORM-embedded-object-issue-td1379137.html

but how to "just call them directly" is not quite clear to me. Any other way of querying the embedded objects in GORM?

like image 841
Ivan Klaric Avatar asked Aug 14 '13 14:08

Ivan Klaric


1 Answers

I finally gave up on the where query and went with the DetachedCriteria approach. Gives me the same flexibility as the where queries, but works with embedded domain objects:

def criteria = new DetachedCriteria(A).build {
    eq 'prop1', 'bla2'
}
criteria = criteria.build {
   eq 'prop3.prop4', 'bla'
}
def list = criteria.list()
like image 97
Ivan Klaric Avatar answered Sep 29 '22 03:09

Ivan Klaric