Skip to content

Instantly share code, notes, and snippets.

@biniama
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biniama/ac2fca32f6a5be2c21c6 to your computer and use it in GitHub Desktop.
Save biniama/ac2fca32f6a5be2c21c6 to your computer and use it in GitHub Desktop.
Example of Using Hibernate Create Criteria for a complex query in Grails
List<Account> getListOfCustomersForSearchCustomer(String firstName, String lastName, String phoneNumber, String accountNumber)
{
return Account.createCriteria().list {
or {
eq("accountNumber", accountNumber)
user {
or {
eq("firstName", firstName)
eq("lastName", lastName)
eq("phoneNumber", phoneNumber)
}
}
}
}
}
}
@biniama
Copy link
Author

biniama commented May 29, 2015

This method RETURNS the list of accounts WHERE Account.accountNumber equals the same as parameter value OR + EITHER firstName, lastName OR phoneNumber are same as User.firstName, User.lastName OR User.phoneNumber.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment