How do I use Criteria to make a join on a date field (in DB2) based on the year.
- by HtmlTableGuru
I have a java.util.Date field in my Object. I would like to use Criteria to select all rows that have a date field with a given year. The SQL would look like the following:
SELECT *
FROM GAME GM
WHERE YEAR(GM.GAME_DATE) = 2010
How can I use Criteria to accomplish this? Thanks in advance.
public Collection<Game> getGamesByDate(Date date){
Collection<Game> games = null;
try {
session.beginTransaction();
Criteria criteria = session.createCriteria(Game.class);
criteria ....
...
...
games = criteria.list();
} catch (HibernateException e) {
e.printStackTrace();
}
return games;
}