1

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'
4

2 回答 2

2
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();
于 2012-10-30T19:50:18.397 回答
1

我正在使用标准 api:发布后,我让它按如下方式工作:

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'"));
于 2012-10-30T20:07:09.303 回答