Reputation: 71
Good evening,
I have a table called Events in my database which has two fields: START_DATE and END_DATE of datatype Date. I have also created a domain class called Event which is like this:
class Event{
Date startDate
Date endDate
static mapping = {
table 'events'
startDate column: 'start_date'
endDate column: 'end_date'
}
}
Then i created an EventsService which queries the databse for events starting and ending between two dates. For the time being I am trying just to fetch the events who are starting between two dates using the code below:
String hql = "select e from Event e where e.startDate >= :startDateMin and e.startDate <= :startDateMax"
params.put("startDateMin",filter.getStartDateMin())
params.put("startDateMax",filter.getStartDateMax())
def results = Event.executeQuery(hql,params,config)
filter is an object i am using to store all the search criteria and config is a map that stores the sotring and paging parameters.
If i just try to fewtch all the events i will get all the events in the database however if i try to execute the query above then i get this exception:
Caused by: org.hibernate.QueryException: could not resolve property: startDate of: ipmt.modules.Event [select e from ipmt.modules.Event e where e.startDate >= :startDateMin and e.startDate <= :startDateMax]
I have tried everything and i can't figure out what is the problem. My database is OracleSQL.
Upvotes: 0
Views: 603
Reputation: 71
Unfortunately your advice didn't work. However I managed to make it work simply by completely changing the names of the two variables to eventStart and eventEnd and mapping them to the columns of the table. I have no idea what went wrong, tried to print in the screen all the properties of the classes to see if a field with the same name was injected at runtime, I searched the inheritance tree but nothing. Before I did that I had tried changing the datatype in the database to Timestamp and all sorts of weird things but nothing worked. So for anyone having the same problem with grails 2.2.1 first try to change the name of the variable.
Thanks however for your time.
Upvotes: 1
Reputation: 2738
It looks like it is not picking up the column name. I've seen some strange issues like this in GORM.
Try this:
Let me know if this helps.
Upvotes: 0