Ruchi
Ruchi

Reputation: 5192

search record using year criteria in hibernate

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

Answers (1)

A.B.Cade
A.B.Cade

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

Related Questions