1

私は netbeans を使用しており、struts と hibernate を統合して単純なアプリケーションでテーブルのすべてのデータを jsp ページに表示したいと考えています。

しかし、私は次のエラーが発生しています

type Exception report

message

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

exception

java.lang.reflect.InvocationTargetException

グラスフィッシュサーバーのログで、次のエラーが表示されます

    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.<init>(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<Question>) session.createQuery("from Question").list();
            session.getTransaction().commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return SUCCESS;
    }

}

誰か助けてください。

4

3 に答える 3

3

Hibernate バージョンと互換性のない asm バージョンがあります互換性のあるバージョンを確認する 1 つの方法は、maven の依存関係 (ここでは hibernate-coreなど) を調べることです。Mavenビルドをしなくても使える方法です。

たとえば、1 つの有効な組み合わせは次のとおりです。

  • 休止状態 3.6.10、
  • cglib 2.2
  • asm 3.1。

より適切な回答が必要な場合は、現在含まれているライブラリに関する情報を共有する必要があります。

于 2012-07-06T11:35:24.210 に答える