hibernate2支持原生sql不
hibernate的版本2支持原生sql不?
看了hibernate的帮助文档,还是找不出可以支持原生sql的方法。
由于维护旧的系统,需要用到。
谢谢。
[解决办法]
支持啊,你找几个例子看看 网上很多
[解决办法]
对于返回集合
this.getHibernateTemplate().executeFind(
new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
List<Long> list = session.createSQLQuery(sql).
list();
return list;
}
});
对于返回不是集合
this.getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
session.createSQLQuery(sql).executeUpdate()
return null;
}
});