Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6734097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:50:54+00:00 2026-05-26T10:50:54+00:00

I am trying to figure out how to make this snip of code work:

  • 0

I am trying to figure out how to make this snip of code work:

def searchString = unchecked.join(",");
        searchString = searchString.replace("\"", "'")
        println("searchString: " + searchString);

        def matches=Employee.executeQuery("select e.id from Employee as e INNER JOIN Education as ed ON e.id = ed.employee_id INNER JOIN education_type AS et ON et.id = ed.type_id WHERE et.name  in (" +searchString + ")");

This is the query string passed to executeQuery

select e.id from Employee as e INNER JOIN Education as ed ON e.id = ed.employee_id INNER JOIN education_type AS et ON et.id = ed.type_id WHERE et.name  in ('AA','BS')

which I can run in SQL Server and it returns the right results, however my grails code complains:

Stacktrace follows:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ON near line 1, column 59 [select e.id from Employee as e INNER JOIN Education as ed ON e.id = ed.employee_id INNER JOIN education_type AS et ON et.id = ed.type_id WHERE et.name  in ('AA','BS')]

So what am I doing wrong? Is it the wrong domain object executing the query?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:50:55+00:00Added an answer on May 26, 2026 at 10:50 am

    HQL is slightly/enough different than standard SQL. Assuming Hibernate knows about the relationship between these objects you can simplify your query to

    List<String> typeNames = unchecked.collect { it.replace("\"", "") }
    String query = """FROM Employee e
                      WHERE e.education.educationType.name IN (:typeNames)"""
    List<Employee> = Employee.executeQuery(query, [typeNames: typeNames])
    

    It’s really important to use either named params or positional params with your query to prevent sql injection. Also if you really just want a list of employee id’s rather than instances you can put the SELECT e.id back in there. There is also no reason to include the quotes since when the params are bound they will use the correct quotes for the database you are working with, given that the above code snippet also stripts out the quotes but you might rethink even letting them be included in the first place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out how to make this code work. Basically i have
I'm trying to figure out how to make this work. Here is my code,
I have been trying to figure out a way to make this work, but
I'm trying to figure out how to make jQuery slide #content2 down and replace
I'm trying to figure out how to make this hack for attr_accessible to support
I'm trying to figure out why this doesn't work. Let's say you three models,
I'm trying to figure out how I can make this page redirect to a
I'm trying to figure out how to make it so that when I'm moving
I'm trying to figure out a way to make demos for a program I've
I've been trying to figure out how I can make a query with MySQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.