2010-03-17 49 views
0

我有这些类。如何搜索内部类?

class Author{ 
    Person person 
} 


class Person{ 
    String lastName 
    String firstName 
    String middleName 
} 

我想查询Person和Author。

def persons = Person.findAllByLastNameiLike("${a}") 

但似乎我不能做

def authors = Author.findAllByPerson(persons) 

任何想法如何,我会做到这一点?

回答

2

上图所示的代码不会与一个单一的对象,而不是收集工作

def authors = Author.findAllByPerson(persons) 

因为findAllBy*作品。要查找Personpersons中包含的任何一个的所有作者,请使用HQL或标准查询。例如,一个(未经测试的)HQL查询看起来像这样:

Author.executeQuery(""" 
    FROM Author a 
    WHERE a.person IN (:people)""", [people: persons]) 
+0

谢谢做了类似的事情。 – Neoryder 2010-03-18 02:31:39