遇到Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]异常

来源:互联网 发布:js产生不重复的随机数 编辑:程序博客网 时间:2024/05/21 07:05

你有遇到这个异常吗?该异常完整语句为:

Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file […….xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer] 


该异常为写一个客户管理系统时遇到的,由小组合作完成的,我负责服务部分。其实这个与这个异常解决没有任何关系,闲话少说。

遇到问题百度,看到第二调解决方案是一个“小樽的雨后”的空间博文,博主可能也是新手,写的博文和我风格一样不出彩。

根据他的解决方案,果断在applicationContext.xml配置文件上下手,该异常发生在hibernate配置上,而我的项目是ssh2框架,数据持久化操作部分都在该配置文件的sessionFactory中配置,检查了下

<property name="mappingResources">
<list>
<value>com/hfxt/entity/TbDty.hbm.xml</value>
<value>com/hfxt/entity/TbService.hbm.xml</value>
<value>com/hfxt/entity/TbCustomer.hbm.xml</value>
</list>
</property>

这里没有任何问题。无法,继续找实体类及其映射配置文件,反正问题就在这里跑不掉的,果然在TbDty.java实体类中发现问题:

private Set tbServices = new HashSet(0);的getter、setter方法被我不小心注释掉了,如是:

public Set getTbServices() {
return this.tbServices;
}

public void setTbServices(Set tbServices) {
this.tbServices = tbServices;
}

取消注释,重新运行,一切ok。


总结,解决问题的思路无非两个,一是搞清楚异常的意思,是什么异常;二是根据异常的类型锁定发生异常的地方。把握这两点,解决异常就不会走弯路,顺利解决。