How do I use Criteria to make a join on a date field (in DB2) based on the year.
Posted
by HtmlTableGuru
on Stack Overflow
See other posts from Stack Overflow
or by HtmlTableGuru
Published on 2010-03-24T18:39:26Z
Indexed on
2010/03/24
18:43 UTC
Read the original article
Hit count: 279
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;
}
© Stack Overflow or respective owner