java session初始化,SEVERE:初始化SessionFactory创建失败.java.lang.NoSuchMethodError:org.objectweb.asm.ClassWrit...

I am using netbeans,

and want to integrate struts and hibernate for a simple application to display all the data of a table on a jsp page.

But i am getting the following error

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.reflect.InvocationTargetException

At the logs of glassfish server i get following error

SEVERE: Initial SessionFactory creation failed.org.hibernate.HibernateException: /hibernate.cfg.xml not found

SEVERE: Initial SessionFactory creation failed.java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.(Z)V

HibernateUtil.java:

package controller;

import org.hibernate.cfg.Configuration;

import org.hibernate.SessionFactory;

/**

* Hibernate Utility class with a convenient method to get Session Factory

* object.

*

* @author ROMO

*/

public class HibernateUtil {

private static final SessionFactory sessionFactory;

static {

try {

// Create the SessionFactory from standard (hibernate.cfg.xml)

// config file.

sessionFactory = new Configuration().configure().buildSessionFactory();

} catch (Throwable ex) {

// Log the exception.

System.err.println("Initial SessionFactory creation failed." + ex);

throw new ExceptionInInitializerError(ex);

}

}

public static SessionFactory getSessionFactory() {

return sessionFactory;

}

}

FindQuestion.java:

package controller;

import beans.Question;

import com.opensymphony.xwork2.ActionSupport;

import java.util.ArrayList;

import java.util.List;

import org.hibernate.Session;

/*

* @author ROMO

*/

public class FindQuestion extends ActionSupport {

private String q = null;

private String categoryname = null;

private List questionList = new ArrayList();

@Override

public String execute() throws Exception {

q = "Question";

categoryname = "Category";

try {

Session session = HibernateUtil.getSessionFactory().getCurrentSession();

session.beginTransaction();

this.questionList = (List) session.createQuery("from Question").list();

session.getTransaction().commit();

} catch (Exception e) {

e.printStackTrace();

}

return SUCCESS;

}

}

Can someone please Help me out.

解决方案

You have asm version that is incompatible with your Hibernate version. One way to check for compatible versions is to take a look to the maven dependencies, here for example for hibernate-core. It is usable way even if you do not maven builds.

One working combination for example is:

Hibernate 3.6.10,

cglib 2.2

asm 3.1.

If you need answer that is more suited for you, you have to share information about which libraries are included at the moment.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值