aspose file tools*
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
Author

Grails Criteria Builder

Gareth Millward
Greenhorn

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 propertyType.id 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)

id
property_name
property_town
property_raod
property_type_id

property_type (table)

id
property_type
description

My search form:



My controller code to handle search

Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Shouldn't this:
eq("propertyType.id", 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
Greenhorn

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
Sheriff

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
Greenhorn

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

Joined: Jan 10, 2002
Posts: 61206
    
  66

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Grails Criteria Builder