2 czbcomeon czbComeOn 于 2016.02.28 15:03 提问

spring整合hibernate出现sessionFactory的bean创建异常错误

图片说明
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:753)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:838)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
at com.guigu.ssh.hibernate.test.SpringHibernateTest.(SpringHibernateTest.java:13)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:195)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:244)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:241)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:185)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)
at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:400)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:372)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:454)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:439)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 34 more
Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:138)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:188)
at org.hibernate.tuple.entity.EntityMetamodel.(EntityMetamodel.java:403)
at org.hibernate.persister.entity.AbstractEntityPersister.(AbstractEntityPersister.java:520)
at org.hibernate.persister.entity.SingleTableEntityPersister.(SingleTableEntityPersister.java:148)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
... 43 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:135)
... 52 more
Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for userName in class com.guigu.ssh.hibernate.entities.Account
at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:310)
at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:304)
at org.hibernate.mapping.Property.getGetter(Property.java:323)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:411)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.(AbstractEntityTuplizer.java:200)
at org.hibernate.tuple.entity.PojoEntityTuplizer.(PojoEntityTuplizer.java:80)
... 57 more

不知道是不是jar包有没有问题

图片说明

3个回答

wojiushiwo945you
wojiushiwo945you   Ds   Rxr 2016.02.29 07:45

说实话,我每次看到大段的异常信息都会莫名的抵触,但是开发久了,就会发现异常信息真的是编程人员忠实的伙伴,它严谨、无情地指出你所有的错误。哪怕是标点、输入法错误的圆角,空格,都是错误根源。
所以,我想补充的是,学会跟异常信息相处吧,如果你能耐心看到最后面的异常根源就会发现错误根源了。get/set方法缺失,检查是否缺失,拼写等。

weixin_39171452
weixin_39171452 感谢
大约 2 个月之前 回复
qq_28135059
qq_28135059   2016.02.28 15:40

Account类的userName字段没有get方法,看下面提示
Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for userName in class com.guigu.ssh.hibernate.entities.Account

czbComeOn
czbComeOn 可以了,谢谢,刚改了个字母,get set方法忘记重新写了
2 年多之前 回复
weixin_39171452
weixin_39171452   2018.05.26 21:09

我也是改了字段然后忘了重新生成getset方法

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
hibernate 与 spring整合,SessionFactory初始化hibernate,Session数据的增删改查
导包 不同于以往的导包,由于我们创建的是maven的webapp项目,所以现在只需配置下pomxml这个配置文件,系统会自动到maven的中央仓库去下载相应的包. 本人的pom.xml配置文件如下(都写有说明的哈):  project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/
Spring创建Hibernate的SessionFactory的简易方法
Spring通过加载整个hibernate.cfg.xml配置文件,实现创建SessionFactory的简易方法
Spring与Hibernate整合之sessionFactory创建出错
报错内容:java.lang.AbstractMethodError: oracle.jdbc.driver.OracleDatabaseMetaData.getJDBCMajorVersion(). 出现这个错误是因为hibernate版本和oracle的驱动不一致导致.多半原因是因为hibernate版本多高.classes12.jar这边oracle驱动包版本过低.可以使用ojdbc6.j
Spring与Hibernate整合时的核心类LocalSessionFactoryBean详解
在Spring与Hibernate整合核心类LocalSessionFactoryBean详解
Spring4整合Hibernate4详细示例
1. Spring整合Hibernate,主要是解决什么问题?        a、让Spring提供的IOC容器来管理Hibernate的SessionFactory        b、让Hibernate使用Spring提供的声明式事物 2. 整合步骤:         新建一个Java工程,并新建用来保存依赖jar包的lib目录       ①.  加入Hibernate支持:
spring整合hibernate中sessionFactory的两种常用引入方式
spring整合hibernate的步骤: 1.创建持久化类和映射文件; 2.创建hibernate的配置文件; 3.写spring的配置文件,引入sessionFactory 4.测试sessionFactory; 5.写dao和service层的接口和类。
spring加载hibernate里的sessionfactory的三种方式
方式1:只加载SessionFactory               方式2:加载数据库连接池          <propertyname="dataSource" ref="dataSource">             方式3:加载所有属性  bean id="sessionFactory" class="org.springframewor
Spring学习(五)spring整合hibernate
上一篇博客中讲到spring dao层对jdbc的封装,用到了模板模式的设计思想 。这篇我们来看看spring中的orm层对hibernate的封装,也就是所谓的spring整合 hibernate。这里同样用了模板模式, 将hibernate开发流程封装在ORM层提供的模板类HibernateTemplate中,通过在DAO中对模板类的使用,实现对传统hibernate开发流程的代替。 一、先来
实例演示如何在spring4.2.2中集成hibernate5.0.2并创建sessionFactory
本文地址:文章作者:苏生米沿本文目的:使用spring4.2.2集成hibernate5.0.2并创建sessionFactory实例。开发环境:eclipse(jee_mars) JDK1.8 MYSQL5.6 spring下载地址: https://repo.spring.io/list/release/org/springframework/spring/4.2.2.RELEASE/环境搭建
Spring4+Hibernate4整合,关于获取SessionFactory
Spring4+Hibernate4整合,修改Dao组件获取session