hibernate 时间条件查询oracle有关问题

hibernate 时间条件查询oracle问题

		res = (List)super.getHibernateTemplate().execute(new HibernateCallback(){

			public Object doInHibernate(Session session)

					throws HibernateException, SQLException {

				// TODO Auto-generated method stub

                 String sql = "select p.* ,q.* from TABLE1 q  right join  TABLE2 p on q.FIELD1 = p.FIELD1 
                                    where p.update_date>?";

				SQLQuery query = session.createSQLQuery(sql);

				List _res = null;

				if(t!=null)
				{
					_res = query.addEntity("p", ENTITY1.class).addEntity("q", ENTITY2.class)
					.setDate(0,t).list();

				}

				return _res;

			}});

  以上当数据库中字段update_time格式是:yyyy-MM-dd HH:mm:ss,采用以上方式查询 update_time 大于某个时间的记录貌似查询条件不起作用,为了尽快解决问题,不纠结于SLQQuery中怎么实现的,后来换了一种方式:

 

    将语句修改为:

java.text.SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dt = format.format(date );
String sql = "select p.* ,q.* from TABLE1 q  right join  
TABLE2 p on q.FIELD1 = p.FIELD1  where 
p.update_date>to_date('"+dt+"','yyyy-mm-dd hh24:mi:ss')";

 

将查询条件去掉:

 

_res = query.addEntity("p", ENTITY1.class).addEntity("q", ENTITY2.class).list();

 

问题暂时得到解决,但是对于hibernate 跨数据表的DAO有点疑虑。