Reputation: 556
Just out of curiosity, what is the best way to accomplish this using hibernate
select *
from USERS
where TO_CHAR(CREATE_TIMESTAMP, 'YYYY-MM-DD HH24:MI:SS.FF') = '1972- 07-31 13:52:50.381000'
Upvotes: 1
Views: 4468
Reputation: 556
I was using the criteria api: Just after posting, I got it to work as follows:
Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(User.class);
criteria.add(Restrictions.sqlRestriction("TO_CHAR(CREATE_TIMESTAMP, 'YYYY-MM-DD HH24:MI:SS.FF')='1972-07-31 13:52:50.381000'"));
Upvotes: 1
Reputation: 692231
Date date = dateFormat.parse("1972-07-31 13:52:50.381");
String hql = "select u from User u where u.createTimestamp = :timestamp";
return session.createQuery(hql).setTimestamp("timestamp", date).list();
Upvotes: 2