求助 hibernate3.0中使用原始的sql

07-11-26 fudong
请问在hibernate3.0不映射实体类能使用原始的sql吗?

下面是个简单的例子:

public List getList()

{

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

Session session = sessionFactory.openSession();

Transaction tx=session.beginTransaction();

String sql="select * from temp5 ";

List list=session.createSQLQuery(sql).list();

tx.commit();

session.close();

return list;

}

List list=session.createSQLQuery(sql).list();出错了,如下:

org.hibernate.QueryException: addEntity() or addScalar() must be called on a sql query before executing the query.

2
fudong
2007-11-26 19:16
找到原因了,原来是hibernate3.0不支持这个方法,把版本换到3.2就OK了

猜你喜欢