File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Application Frameworks and the fly likes Grails Criteria Builder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Grails Criteria Builder" Watch "Grails Criteria Builder" New topic

Grails Criteria Builder

Gareth Millward

Joined: Jun 28, 2008
Posts: 5
Hi All,

My first post on the forum! I have a real problem. I am trying to do a search on a object that references another table. But for the life of me I can not seem to search on the object. However I can build a search on the town, road, fields etc. I have tried to do a join and all-sorts, it just ends up bringing back all the results from the database. Any advice would be appreciated.

I have a 2 tables:

property (table)


property_type (table)


My search form:

My controller code to handle search

Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

Shouldn't this:
eq("", Integer.parseInt(params.propertyTypeId) )

be this?:
eq("property_type_id", Integer.parseInt(params.propertyTypeId) )
[ September 29, 2008: Message edited by: Marc Peabody ]

A good workman is known by his tools.
Gareth Millward

Joined: Jun 28, 2008
Posts: 5
Hi, thanks for the help...
I gave it a try and altered the query a little, I also put in a search by town from the property table which worked fine. Still though trying to search using the property_type_id which holds a integer mapping to the property_type table i still have a problem

Putting in the property_type_id like you suggested yielded the following:

Message: could not resolve property: property_type_id of: Property
Caused by: org.hibernate.QueryException: could not resolve property: property_type_id of: Property
Class: PropHomeController
At Line: [45]
Code Snippet:

The code in the controller is:

def search = {

//def property = Property.get()

if (request.method == 'GET') {

def criteria = Property.createCriteria()
def results = criteria.list {
like("town", "Almancil%")
and {
eq("property_type_id", '%' + params.propertyTypeId + '%')
render(view:'search', model:[ propertyList: results])
Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

If you're using % characters I think you have to use like, not eq.

Also, your display name used to match our naming policy of a first and last name but now it's different. Please update your profile to change it back to a valid name.

There's currently a bug in Google Chrome that if you ask it to remember your password and then you visit the page to update your JavaRanch profile, Chrome will actually replace your Display Name with your user id. If you use Chrome, that might have been the problem. Thanks in advance for fixing your display name.
Gareth Millward

Joined: Jun 28, 2008
Posts: 5
Fixed that not sure what happened.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60774

"Gareth", please check your private messages for an important administrative matter.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
wood burning stoves
subject: Grails Criteria Builder
Similar Threads
[Grails] Add form elements with javascript
Saving object having many-to-many relationship in grails
How to get property value for IF?
Getting search results on same search page
Forms and Table cells - are they compatible?