5

I am developing a web application using Hibernate framework. I got this error when trying to run webapp.

Error Console:

Exception caught in Create Account Dataorg.hibernate.HibernateException: Unable to
instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
java.lang.NullPointerException

My mapping file (hbm.xml) :

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.vgec.bean.CreateAccount" table="CreateAccount" >
        <id name="enrollment_number" type="java.lang.String">
            <column name="enrollment_number" length="20"/>
            <generator class="assigned" />
        </id>
       <property name="activation_code" type="java.lang.String">
        <column name="activation_code" length="50"/>
       </property>


</class>
</hibernate-mapping>

DataAccessObject file code:

public void addCreateAccount(CreateAccount act) throws Exception {

    Session session = null;

    try{
        //this step will read hibernate.cfg.xml
        SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
        session = sessionFactory.openSession();
        Transaction tx = session.beginTransaction();
        session.save(act);
        tx.commit();

    }catch(Exception e) {
        System.out.println("Exception caught in Create Account Data" + e);
    }finally{
        session.flush();
        session.close();
    }

}

Here in Above code Exception is thrown - the string in catch is displayed in the error in console.

Here is my bean Or POJO file:

package org.vgec.bean;

public class CreateAccount {

    private String enrollment_number;
    private String activation_code;

    public String getEnrollment_number() {
        return enrollment_number;
    }

    public void setEnrollment_number(String enrollment_number) {
        this.enrollment_number = enrollment_number;
    }

    public String getActivation_code() {
        return activation_code;
    }

    public void setActivation_code(String activation_code) {
        this.activation_code = activation_code;
    }

}
  • I have checked the other threads solutions.
  • I have included javaassist.jar file
  • All the setter and getter do not have any typos.
  • I'm also having java.lang.NullPointerException.

What is the root cause of this error?

blackpanther
  • 10,998
  • 11
  • 48
  • 78
Parth
  • 141
  • 1
  • 2
  • 14
  • Try explicitly define no-arg constructor for CreateAccount – Alex Turbin Apr 15 '13 at 19:46
  • Have you got any constructor for the POJO? – blackpanther Apr 16 '13 at 07:10
  • Thanks!! @AlexStamper, blackpanther. That's worked for me.But don't know why , I haven't made any constructor before then what is the reason for that error. because it doesn't matter if we add no-arg constructor or not – Parth Apr 17 '13 at 15:17
  • You're welcome! I will post this as answer, to make it clear for further watchers of the question or someone having same problems. – Alex Turbin Apr 18 '13 at 21:59

2 Answers2

1

You should explicitly define no-arg constructor. This is a requirement from Hibernate to all POJOs.

Detailed explanation could be found here: https://stackoverflow.com/a/2971717/283426

Community
  • 1
  • 1
Alex Turbin
  • 2,554
  • 2
  • 22
  • 35
-1

that is right you need to have a constructor with no argument so it enables to initiate an object with the controller and as well as service class or anyway you are using that object.

Kishan Bheemajiyani
  • 3,429
  • 5
  • 34
  • 68
  • 5
    This is not an answer at all. You can see that from the way it starts even. "That is right....". It's obviously a comment to the previous answer. Please keep comments as comments and answers as answers. – andho Oct 16 '13 at 07:05