Announcement Announcement Module
Collapse
No announcement yet.
spring3.2 and hibernate4.1.9 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring3.2 and hibernate4.1.9

    today,i use spring3.2 and hibernate4.1.9,
    when i use HibernateTemplate,
    throw ClassCastException,i want to know why? Thanks.
    英语不是太好,凑合看吧。
    see:
    严重: Exception occurred during processing request: org.springframework.orm.hibernate4.SessionHolder cannot be cast to org.springframework.orm.hibernate3.SessionHolder
    java.lang.ClassCastException: org.springframework.orm.hibernate4.SessionHolder cannot be cast to org.springframework.orm.hibernate3.SessionHolder
    at org.springframework.orm.hibernate3.SessionFactoryU tils.doGetSession(SessionFactoryUtils.java:289)
    at org.springframework.orm.hibernate3.SessionFactoryU tils.getSession(SessionFactoryUtils.java:235)
    at org.springframework.orm.hibernate3.HibernateTempla te.getSession(HibernateTemplate.java:457)
    at org.springframework.orm.hibernate3.HibernateTempla te.doExecute(HibernateTemplate.java:392)
    at org.springframework.orm.hibernate3.HibernateTempla te.executeWithNativeSession(HibernateTemplate.java :374)
    at org.springframework.orm.hibernate3.HibernateTempla te.find(HibernateTemplate.java:912)
    at org.springframework.orm.hibernate3.HibernateTempla te.find(HibernateTemplate.java:904)
    at com.dao.impl.ManDAOImpl.showManList(ManDAOImpl.jav a:14)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:317)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:183)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :150)
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:110)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :172)
    at org.springframework.aop.interceptor.ExposeInvocati onInterceptor.invoke(ExposeInvocationInterceptor.j ava:90)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :172)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy6.showManList(Unknown Source)
    at com.service.impl.ManServiceImpl.showManList(ManSer viceImpl.java:15)
    at com.action.ManAction.getManList(ManAction.java:17)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.opensymphony.xwork2.DefaultActionInvocation.in vokeAction(DefaultActionInvocation.java:446)
    at com.opensymphony.xwork2.DefaultActionInvocation.in vokeActionOnly(DefaultActionInvocation.java:285)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:248)
    at org.apache.struts2.interceptor.debugging.Debugging Interceptor.intercept(DebuggingInterceptor.java:25 6)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:242)
    at com.opensymphony.xwork2.interceptor.DefaultWorkflo wInterceptor.doIntercept(DefaultWorkflowIntercepto r.java:176)
    at com.opensymphony.xwork2.interceptor.MethodFilterIn terceptor.intercept(MethodFilterInterceptor.java:9 8)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:242)
    at com.opensymphony.xwork2.validator.ValidationInterc eptor.doIntercept(ValidationInterceptor.java:265)
    at org.apache.struts2.interceptor.validation.Annotati onValidationInterceptor.doIntercept(AnnotationVali dationInterceptor.java:68)
    at com.opensymphony.xwork2.interceptor.MethodFilterIn terceptor.intercept(MethodFilterInterceptor.java:9 8)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:242)
    at com.opensymphony.xwork2.interceptor.ConversionErro rInterceptor.intercept(ConversionErrorInterceptor. java:138)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:242)
    at com.opensymphony.xwork2.interceptor.ParametersInte rceptor.doIntercept(ParametersInterceptor.java:238 )
    at com.opensymphony.xwork2.interceptor.MethodFilterIn terceptor.intercept(MethodFilterInterceptor.java:9 8)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:242)
    at com.opensymphony.xwork2.interceptor.ParametersInte rceptor.doIntercept(ParametersInterceptor.java:238 )
    at com.opensymphony.xwork2.interceptor.MethodFilterIn terceptor.intercept(MethodFilterInterceptor.java:9 8)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:242)
    at com.opensymphony.xwork2.interceptor.StaticParamete rsInterceptor.intercept(StaticParametersIntercepto r.java:191)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:242)
    at org.apache.struts2.interceptor.MultiselectIntercep tor.intercept(MultiselectInterceptor.java:75)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:242)
    at org.apache.struts2.interceptor.CheckboxInterceptor .intercept(CheckboxInterceptor.java:90)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:242)
    at org.apache.struts2.interceptor.FileUploadIntercept or.intercept(FileUploadInterceptor.java:252)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:242)
    at com.opensymphony.xwork2.interceptor.ModelDrivenInt erceptor.intercept(ModelDrivenInterceptor.java:100 )
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:242)
    at com.opensymphony.xwork2.interceptor.ScopedModelDri venInterceptor.intercept(ScopedModelDrivenIntercep tor.java:141)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:242)
    at com.opensymphony.xwork2.interceptor.ChainingInterc eptor.intercept(ChainingInterceptor.java:145)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:242)
    at com.opensymphony.xwork2.interceptor.PrepareInterce ptor.doIntercept(PrepareInterceptor.java:171)
    at com.opensymphony.xwork2.interceptor.MethodFilterIn terceptor.intercept(MethodFilterInterceptor.java:9 8)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:242)
    at com.opensymphony.xwork2.interceptor.I18nIntercepto r.intercept(I18nInterceptor.java:176)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:242)
    at org.apache.struts2.interceptor.ServletConfigInterc eptor.intercept(ServletConfigInterceptor.java:164)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:242)
    at com.opensymphony.xwork2.interceptor.AliasIntercept or.intercept(AliasInterceptor.java:193)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:242)
    at com.opensymphony.xwork2.interceptor.ExceptionMappi ngInterceptor.intercept(ExceptionMappingIntercepto r.java:187)
    at com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:242)
    at org.apache.struts2.impl.StrutsActionProxy.execute( StrutsActionProxy.java:54)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAc tion(Dispatcher.java:544)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations .executeAction(ExecuteOperations.java:77)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrep areAndExecuteFilter.doFilter(StrutsPrepareAndExecu teFilter.java:91)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)

    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:103)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:861)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:606)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:619)

  • #2
    I think, its better you see the stack-trace you sent. Its clear that you're using different classes which are not compatible and therefore there's error. You gotto either using hibernate4 specific SPRING classes or use hibernate 3.X

    Comment


    • #3
      You'll find that, while Spring 3.2 supports Hibernate 4, Spring 3.2 doesn't provide Hibernate 4 versions of HibernateTemplate, HibernateDaoSupport, etc.

      In theory, this is a good thing. However, if you've built an entire DAO infrastructure using these *hibernate3.* artifacts, you'll be unpleasantly surprised by how broken your application will be when moving to Spring 3.2 and Hibernate 4. Even the classes that are supposed to support Hibernate 4 don't have the same public APIs as their hibernate3 versions.

      For instance, compare the JavaDocs of hibernate4.SessionFactoryUtils and hibernate3.SessionFactoryUtils.

      As you'll see, if your app has been using SessionFactoryUtils.getSession() to get a Hibernate Session bound to the current thread, you can't just switch to hibernate4.SessionFactoryUtils because there is no longer a getSession() method! Even if this behavior is being handled by Hibernate's SessionFactory or the Spring LocalSessionFactoryBean, it would have been nice for SpringSource to leave the method on SessionFactoryUtils and just delegate to the object doing the real work. That would have minimized some of the rework of applications migrating to Spring 3.2 and Hibernate 4.x.

      FWIW, I finally got Spring 3.2.0 + Hibernate 4.1.9 working now (still with some unanswered questions). Despite it not being as smooth a migration as I'd hoped it would be, it isn't insurmountable, so hang in there!

      --
      jack

      Comment

      Working...
      X