简体   繁体   中英

HQL Query syntax in grails

I am trying to get a list of employees that have multiple "Education" which each have an "Education type"

so Employee has a collection of educations, which each have an type which have a name.

    def unchecked = educationTypes?.unchecked
    String query = "FROM Employee e, IN (e.education)  AS ed WHERE ed.type.name IN (:typeNames)";

    def matches = Employee.executeQuery(query, [typeNames: unchecked]);

The query above give me the following:

Stacktrace follows:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ed near line 1, column 39 [FROM Employee e, IN (e.education)  AS ed WHERE ed.type.name IN (:typeNames)]
    at $Proxy12.createQuery(Unknown Source)

So I am trying to figure out how to access this correctly. Much appreciation for any help

Try something like this:

Employee.executeQuery("""
    select e from Employee e, Education ed 
    where ed.employee = e and ed.type.name IN (:typeNames)
""", [typeNames: [...]])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM