Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

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?

like image 922
Parth Avatar asked Nov 24 '22 01:11

Parth


1 Answers

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

like image 101
Alex Turbin Avatar answered Feb 03 '23 06:02

Alex Turbin