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

假装没事ソ 提交于 2019-12-30 09:32:49

问题


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?


回答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




回答2:


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.



来源:https://stackoverflow.com/questions/15930495/org-hibernate-hibernateexception-unable-to-instantiate-default-tuplizer-org-hi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!