#SSH#ognl.MethodFailedException: Method "login" failed for object action.UserAction@13848bc [java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;]

ognl.MethodFailedException: Method "login" failed for object action.UserAction@13848bc [java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;]
hibernate版本太高已不支持getHibernateTemplate下面方法操作数据库

    public Query createQuery(String hql) {
        return this.getSession().createQuery(hql);
    }

    public void delete(T baseBean) {
        this.getHibernateTemplate().delete(baseBean);
    }

    public List list(String hql) {
        return this.getHibernateTemplate().find(hql);
    }

    public int getTotalCount(String hql, Object... params) {
        Query query = this.createQuery(hql);

        for(int i = 0; params != null && i < params.length; ++i) {
            query.setParameter(i + 1, params[i]);
        }

        Object obj = this.createQuery(hql).uniqueResult();
        return ((Long)obj).intValue();
    }

换成sessionfactory方法操作事务

    public UserEntity findByUsernameAndPassword(UserEntity userEntity) {

        Session s = sessionFactory.openSession();
        Transaction tx= s.beginTransaction();
        userEntity.setUsername("1");
        userEntity.setPassword("2");
        System.out.println("3");
        s.save(userEntity);
        tx.commit();
        return null;
    }

你可能感兴趣的:(#SSH#ognl.MethodFailedException: Method "login" failed for object action.UserAction@13848bc [java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;])