Reputation: 5192
I need all records which have year entered from search criteria.
for ex: String year = "2012";
In hibernate how it work ?
criteria.add(Restrictions.like("createDate", "%"+year+"%"));
createDate is fetch in format DD-MM-YY from oracle database.
Please suggest..
Upvotes: 0
Views: 1804
Reputation: 16905
Try something like:
criteria.add(Restrictions.sqlRestriction("to_char({alias}.CREATE_DATE, 'yyyy') = ?", year, Hibernate.STRING));
I'm assuming that the name of the column mapped to createDate
is CREATE_DATE
Upvotes: 2