本文介绍了org.hibernate.HibernateException:无法实例化默认tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在使用Hibernate框架开发Web应用程序。尝试运行webapp时出现此错误。 错误控制台: 创建帐户中捕获的异常Dataorg.hibernate.HibernateException:无法实例化默认tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer] java.lang.NullPointerException 我的映射文件(hbm.xml): <?xml version =1.0encoding =utf-8?> <!DOCTYPE hibernate-mapping PUBLIC - // Hibernate / Hibernate Mapping DTD 3.0 // ENhttp://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd\"> ; < hibernate-mapping> < class name =org.vgec.bean.CreateAccounttable =CreateAccount> < id name =enrollment_numbertype =java.lang.String> < column name =enrollment_numberlength =20/> < generator class =assigned/> < / id> < property name =activation_codetype =java.lang.String> < column name =activation_codelength =50/> < / property> < / class> < / hibernate-mapping> DataAccessObject文件代码: public void addCreateAccount(CreateAccount act)throws Exception { Session session = null; try { //这一步将读取hibernate.cfg.xml SessionFactory sessionFactory = new Configuration()。configure()。buildSessionFactory(); session = sessionFactory.openSession(); 交易tx = session.beginTransaction(); session.save(act); tx.commit(); } catch(例外e){ System.out.println(创建帐户数据中的异常+ e); }最后{ session.flush(); session.close(); } } 此处上面的代码抛出异常 - catch中的字符串显示在控制台的错误中。 这是我的bean或POJO文件: package org.vgec.bean; 公共类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; } } 我检查了其他线程的解决方案。 我已经包含了 javaassist.jar 文件 所有的setter和getter都没有任何错别字。 我也有 java.lang.NullPointerException 。 这个错误的根本原因是什么?解决方案你应该明确定义no-arg构造函数。这是从Hibernate到所有POJO的要求。 详细说明可在此处找到: https://stackoverflow.com/a/2971717/283426 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 toinstantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]java.lang.NullPointerExceptionMy 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 fileAll the setter and getter do not have any typos.I'm also having java.lang.NullPointerException.What is the root cause of this error? 解决方案 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 这篇关于org.hibernate.HibernateException:无法实例化默认tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-23 08:20