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

问题描述

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包有没有问题

解决方案

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

解决方案二:

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

时间: 2024-10-31 00:22:48

spring整合hibernate出现sessionFactory的bean创建异常错误的相关文章

spring 整合hibernate出错

问题描述 spring 整合hibernate出错 <?xml version ="1.0" encoding ="utf-8"?> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.

java-测试Spring整合hibernate/Struts2框架时,配置文件报奇怪的错误,求解

问题描述 测试Spring整合hibernate/Struts2框架时,配置文件报奇怪的错误,求解 为什么会报无法识别property? 解决方案 怎么都是这种问题,property要包含在bean标签内 解决方案二: Struts2+hibernate+spring整合时错误Struts2+hibernate+spring整合时错误 解决方案三: http://iteye.blog.163.com/blog/static/186308096201210265334689/ 解决方案四: pro

用spring整合hibernate问题

问题描述 刚刚学习spring,找了段视频看看-想先配置下,不知道哪里错了(spring 1.2和2.0的差别?)下面是我的配置文件applicationContext.xml<?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org

ssh整合-spring整合hibernate做测试时没有报错,当三个整合时启动就报错啦,求大神指点!!

问题描述 spring整合hibernate做测试时没有报错,当三个整合时启动就报错啦,求大神指点!! 报的错误org.springframework.scheduling.quartz.JobMethodInvocationFailedException: Invocation of method 'ecsUnsigned' on target class [class $Proxy17] failed; nested exception is org.springframework.tran

spring整合hibernate出错!!!

问题描述 spring整合hibernate出错!!! 老是报图片中的错误,不知道是不是版本的问题,我的是jdk1.8.求大神们给我解决下,感激不尽!!! 解决方案 应该是哪里的路径配置不对吧,检查下hibernate.cfg.xml和applicationContext.xml,全限定名写没写错. 解决方案二: 如果是spring和mybatis整合,可参考:http://git.oschina.net/wangkang/llsfw 希望能够帮到你. 解决方案三: 看下你的配置文件怎么写的,,

【spring框架】spring整合hibernate初步

spring与hibernate做整合的时候,首先我们要获得sessionFactory. 我们一般只需要操作一个sessionFactory,也就是一个"单例",这一点很适合交给spring来管理. 下面的代码演示如何创建一个JDBC DataSource 和Hibernate SessionFactory: <beans> <bean id="myDataSource" class="org.apache.commons.dbcp.B

spring整合hibernate

问题描述 初学spring与hibernate,尝试整合时,发现添加的数据提交不到数据库,请高手们帮忙看一下出了什么问题....下面提供hibernate与spring配置的源码,我的思路是让hibernate独揽数据库的配置,spring用于分离其事务.分离开hibernate与spring的配置文件,让配置更清晰.hibernate.cfg.xml:<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEhib

Spring整合Hibernate,取不到hibernateTemplate的值,求助!

问题描述 <hibernate-configuration><session-factory><propertyname="connection.driver_class">com.mysql.jdbc.Driver</property><propertyname="connection.url">jdbc:mysql://localhost:3306/bbs</property><pro

ssh框架中spring整合hibernate的配置文件模板(带详细注释)

applicationContext.xml的配置文件模板 1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans 3 xmlns="http://www.springframework.org/schema/beans" 4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 5 xmlns:aop=&quo