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 7557975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:16:20+00:00 2026-05-30T12:16:20+00:00

Trying to simply run a query of domain objects using find all and it’s

  • 0

Trying to simply run a query of domain objects using find all and it’s not acting as I would expect:

searchResults = Contact.findAll("from Contact as c where c.company=${params.company.id} and c.firstName = '%${nameSearch}%'  or c.lastName = '%${nameSearch}%' ")

I want to find all people within a company that have a first name or last name similar to the search that was entered (params.search was stored into nameSearch variable). If I change the value for first or last to a particular name “Tim” or “Johnson”, it works.

What am I doing incorrectly with the variable or “like” reference? I thought the % symbol was basically the * symbol in search criteria?

I’ve tried the 2.0.0 form of search:

        searchResults = Contact.findAll{
            company == params.company.id
            firstName == '%' + nameSearch + '%'
            lastName == '%' + nameSearch + '%'
        }

But that didn’t work either. Thank you for all help

  • 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-30T12:16:21+00:00Added an answer on May 30, 2026 at 12:16 pm

    Give this a try:

    def company = Company.get(params.company.id)
    def searchResults = Contact.withCriteria {
        eq('company', company)
        or {
            ilike('firstName', '%' + nameSearch + '%')
            ilike('lastName', '%' + nameSearch + '%')
        }
    }
    

    If you don’t want to retrieve the Company instance, you could use idEq() within a company { } block instead.


    A few things (of perhaps more) that were wrong with your HQL attempt:

    • Your company condition was comparing an object (c.company) to an id value (params.company.id)
    • You needed to group your boolean logic correctly, i.e. (company AND (first OR last)), instead of (company AND first OR last)
    • You should have been using like instead of =, e.g. firstName like '%something%'

    As a matter of security, you really, really shouldn’t be building your HQL statement with the values inline. You should use named parameters instead. Check out some of the middle examples in the findAll documentation.

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

Sidebar

Related Questions

I'm simply trying to run a query to find all the records in a
I am trying to run this simple SELECT query using PDO::MySQL, but it does
I'm trying to run a simple query with $this->db in Kohana, but am running
I'm trying to run jetty without building the whole project, but simply point jetty
I am trying to run a simple linear regression (using rpy2 from Python) and
I am using Python 2.6 and am trying to run a simple random number
I am trying to connect to a remote sql database and simply run the
I am trying to run this query on http://dbpedia.org/sparql but I get an error
I am trying to get an insert/return primary key SQL query to run. The
I am trying to setup Fitnesse to run a simple query and I am

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.