session.createQuery()不执行和java.lang.reflect.InvocationTargetException

  今天写SSH的工程的时候,执行到一个DAO中的Query query = session.createQuery(hql)的时候,没有成功执行,直接跳到了finally,然后前台报了500和java.lang.reflect.InvocationTargetException的错误。

  代码如下:

package dao;

import java.util.List;

import model.AccountInfo;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction; import util.HibernateUtil; public class AccountDao {
public Boolean checkPassword(String account,String password){
Session session = HibernateUtil.getSession();
Transaction tran = null;
List<AccountInfo> list = null;
try{
tran = session.beginTransaction();
String hql="from AccountInfo as a where a.account=:username";
Query query = session.createQuery(hql);
query.setString("username",account);
list = query.list();
tran.commit();
}catch(HibernateException he){
tran.rollback();
he.printStackTrace();
}finally{
session.close();
}
if( list.size()==0 || !password.equals(list.get(0).getPassword()) )
return false;
else
return true;
}
}

  然而实际上跟代码没有卵关系"( ̄▽ ̄)"""。是我用MyEclipse安装的hibernate4的lib的antlr-2.7.7.jar和struts2的lib的antlr-2.7.2.jar冲突了,删除后者即可。

上一篇:SSH执行hql报错:Caused by: org.hibernate.hql.ast.QuerySyntaxException: user is not mapped [from user where username = ?]


下一篇:python mysql program