zoukankan      html  css  js  c++  java
  • 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冲突了,删除后者即可。

  • 相关阅读:
    【JZOJ3188】找数【数论,数学】
    【JZOJ3187】的士【模拟】
    【JZOJ3187】的士【模拟】
    【洛谷P1641】生成字符串【数论,数学】
    【洛谷P1896】互不侵犯【状压dp】
    聚集索引与非聚集索引
    哈希索引
    索引能提高检索速度,降低维护速度
    MySQL索引基本知识
    注解
  • 原文地址:https://www.cnblogs.com/lucio_yz/p/4811281.html
Copyright © 2011-2022 走看看