Hibernate 3.0
Hi,
Sorry if this is an obvious question. i just can't find the answer anywhere.
I am trying to query a database table on a date field column. That works ok if i put in all of the data in the date but how can i set the query to return all the dates for a year for exaple? How can i 'wildcard' a field.
I have a field in a POJO containg a date that i set with this code..
Code:
session = this.getHibernateSession() ;
Transaction tx = session.beginTransaction() ;
CalendarEvent ce = new CalendarEvent( ) ;
// ORGANISE DATE
calendar = Calendar.getInstance() ;
calendar.clear() ;
calendar.set( Calendar.YEAR , 2005 ) ;
calendar.set( Calendar.MONTH , new Integer( month ).intValue() ) ;
calendar.set( Calendar.DATE , new Integer( day ).intValue() ) ;
// SET THE VALUES
ce.setShortDesc( shortDesc ) ;
ce.setLongDesc( longDesc ) ;
ce.setDate( calendar ) ;
session.save( ce ) ;
tx.commit();
That works OK.
I can recall the objects, CalendarEvent, OK by searching on the datefield like so...
Code:
session = this.getHibernateSession() ;
Query query = session.createQuery( "select ce from CalendarEvent ce where ce.date = :date" ) ;
Calendar calendar = Calendar.getInstance();
calendar.clear() ;
calendar.set( Calendar.YEAR , 2005 ) ;
calendar.set( Calendar.MONTH , new Integer( month ).intValue() ) ;
calendar.set( Calendar.DATE , new Integer( day ).intValue() ) ;
query.setParameter( "date" , calendar ) ;
but i cannot seem to just enter the year on a query and get all entries for that year. i.e. removing the
Code:
calendar.set( Calendar.MONTH , new Integer( month ).intValue() ) ;
calendar.set( Calendar.DATE , new Integer( day ).intValue() ) ;
lines
can you help.
Thanks,
David.