使用Hibernate无法读取数据,报错“count not execute query”。高手请进。
我照着网上的一个例子,用MyEclipse做一个Struts+Hibernate的简单例子。
Hibernate所需的持久化类(名字叫“Yaopin”,对应库中的表名是“yaopin”),配置文件都用Myeclipse自动生成了。
现在要使用Hibernate来查询数据,出现错误。具体代码如下:
public List getYpList() {
Session session = null;
try {
session = SessionFactory.currentSession();
//跟踪代码发现,session是有值得,不为null
//List list=session.createCriteria(Yaopin.class).list();
List list=session.createQuery("from Yaopin").list();
//用这两种方法都无法读出数据来,报错“count not execute query”
return list;
} catch (HibernateException e) {
System.err.println("HibernateException:" + e.getMessage());
throw new RuntimeException();
} finally {
if (session != null) {
try {
SessionFactory.closeSession();
} catch (HibernateException e) {
}
session = null;
}
}
}
如果需要看hibernate的配置文件,我可以贴出来