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

fudong發表於2007-11-26
請問在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.

相關文章