spring 3.1 整合hibernate 4.0中遇到的问题,求解!谢谢。

冷俊不惊 2012-03-20 10:12:19
在 beans.xml中:
sessionfactory为如下配置:
<bean id="sf" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" destroy-method="clone">
hibernatetemplate为如下配置:
<bean id="hibernateTemple" class="org.springframework.orm.hibernate3.HibernateTemplate">

运行的时候就出问题了。
java.lang.ClassCastException: org.springframework.orm.hibernate4.SessionHolder cannot be cast to org.springframework.orm.hibernate3.SessionHolder
at org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:289)
at org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(SessionFactoryUtils.java:235)
at org.springframework.orm.hibernate3.HibernateTemplate.getSession(HibernateTemplate.java:457)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:393)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:683)
at com.yanrt.spring.impl.UserDAOImpl.Save(UserDAOImpl.java:70)
at com.yanrt.spring.server.UserServer.SaveUser(UserServer.java:55)
at com.yanrt.spring.server.UserServer$$FastClassByCGLIB$$4fbaef0b.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
at com.yanrt.spring.server.UserServer$$EnhancerByCGLIB$$36143ed7.SaveUser(<generated>)
at com.yanrt.spring.server.UserServerTest.testSaveUser(UserServerTest.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
请教
java.lang.ClassCastException: org.springframework.orm.hibernate4.SessionHolder cannot be cast to org.springframework.orm.hibernate3.SessionHolder
这个问题如何解决。
hibernate4.0的包里面没有 org.springframework.orm.hibernate3.HibernateTemplate.
纠结中,求解答,谢谢!
.

...全文
746 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
五哥 2012-03-20
  • 打赏
  • 举报
回复
版本问题吧

java.lang.ClassCastException: org.springframework.orm.hibernate4.SessionHolder cannot be cast to org.springframework.orm.hibernate3.SessionHolder

类型转换异常 ClassCastException
冷俊不惊 2012-03-20
  • 打赏
  • 举报
回复
估计是版本之间的问题,我过还是想看看,能不能解决!
冷俊不惊 2012-03-20
  • 打赏
  • 举报
回复
最后一点写错了:hibernate4.0的包里面没有 org.springframework.orm.hibernate4.HibernateTemplate.
dever2011 2012-03-20
  • 打赏
  • 举报
回复
建议你不要用太高的版本一般spring2.5,hibernate3的,

sessionfactory为如下配置:
<bean id="sf" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" destroy-method="clone">
hibernatetemplate为如下配置:
<bean id="hibernateTemple" class="org.springframework.orm.hibernate3.HibernateTemplate">


看看你的配置
冷俊不惊 2012-03-20
  • 打赏
  • 举报
回复
问题找到了。http://topic.csdn.net/u/20111225/17/3b3e0696-fd71-4da6-9c48-d03ea898ef23.html

67,511

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧