1

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.<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;
    }

}

Can someone please Help me out.

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

9 Comments

i am actually very new to hibernate and maven. Can u please elaborate what exactly i need to do. On the link i am getting a list of hibernate binary versions but no idea what to do with it.
Hard to say exactly what is wrong without your full pom.xml file. Runtime your code expects to able to constructor in org.objectweb.asm.ClassWriter. That seems to be impossible because version of asm you have does not have such a constructor. Incompatible version version can come indirectly via some other dependency in pom.xml.
I am not finding my pom.xml file as i am using netbeans not eclipse. And i dont know which asm is needed to be loaded. I also dont know anything how to deal with maven dependencies. I am frustrated for last 3 days. Please help.
How you manage your dependencies does not really matter. Point with maven repository was to show one place where you can find compatible versions. Answer contains now set working set Hibernate+asm+cglib.
As u said to resolve dependencies i need to update library. But when i replaced asm.jar with asm 1.5.3.jar i get the following error C:\Documents and Settings\ROMO\My Documents\NetBeansProjects\ATest\nbproject\build-impl.xml:709: Warning: Could not find file C:\Documents and Settings\ROMO\My Documents\NetBeansProjects\ATest\lib\hibernate-persistence\asm.jar to copy. Please help what to do. And guide what is proper way to update the hibernate libraries. I am using netbeans 7.1.2.
|
1

I found this:

http://www.hildeberto.com/2008/05/hibernate-and-jersey-conflict-on.html

Essentially, just in case the full explanation above goes: I Fixed classloading issues with asm by using the cglib-nodep-2.2.3.jar. The reason why this needs replacing is that ASM is a popular library. Hibernate is built against asm 1.5.3 but asm is now at version 4. Somewhere, the class loaders in my container are picking up a much more recent version of asm and the class ClassWriter has been changed. Hibernate uses cglib under the covers, which in turn uses asm 1.5.3. This is the issue. cglib-nodep was built to fix this issue. The asm classes have been moved from their standard package to a cglib package and it is these cglib versions that are used by the nodep library.

Spring adopts a very similar approach.

Comments

1

Simply add to your pom.xml :

<dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib-asm</artifactId>
        <version>1.0</version>
</dependency>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.