报出异常:net.sf.hibernate.JDBCException: Could not execute query
连上数据库没有问题的
请看代码:
private void test() throws HibernateException,QueryException{
System.out.println("testing the hibernate.....");
Session session = HibernateSessionFactory.currentSession();
Transaction transaction = session.beginTransaction();
Query query = session.createQuery("from jiveid");
System.out.println("flag in action");
for(Iterator iterator = query.iterate();iterator.hasNext();){
System.out.println("flag in for statemant");
Jiveid jiveid =(Jiveid)iterator.next();
System.out.println("idtype is :" + jiveid.getIdtype());
}
// System.out.println("ifConnected: " + session.isConnected());
// System.out.println("ifOpen :" + session.isOpen());
// System.out.println("ifDirty :" + session.isDirty());
// List l = session.find("FROM jiveid");
// //List l = q.list();
// for (int i=0; i< l.size(); i++) {
// Long id = (Long) l.get(i);
// System.out.println(id.longValue());
// }
transaction.commit();
HibernateSessionFactory.closeSession();
}
------解决方法--------------------------------------------------------
Query query = session.createQuery("from jiveid");
改成
Query query = session.createQuery("select jiveid from Jiveid as jiveid");试试!!