0

I have successfully reached(debugging) a remote service I created that will create a user in another application, however it blows up on the line applicationUserDao.save(user); with this error:

java.lang.LinkageError: loader constraint violation: when resolving interface method "org.hibernate.engine.SessionFactoryImplementor.getTransactionManager()Ljavax/transaction/TransactionManager;" the class loader (instance of org/apache/catalina/loader/WebappClassLoader) of the current class, org/springframework/orm/hibernate3/SessionFactoryUtils, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, org/hibernate/engine/SessionFactoryImplementor, have different Class objects for the type javax/transaction/TransactionManager used in the signature
at org.springframework.orm.hibernate3.SessionFactoryUtils.getJtaTransactionManager(SessionFactoryUtils.java:174)
at org.springframework.orm.hibernate3.SessionFactoryUtils.registerJtaSynchronization(SessionFactoryUtils.java:449)
at org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:350)
at org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:258)
at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:61)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:574)
at com.cambium.bookshelf.dao.AbstractDao.save(AbstractDao.java:59)
at com.cambium.bookshelf.services.ElibraryServiceImpl.createUser(ElibraryServiceImpl.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.remoting.support.RemoteInvocationTraceInterceptor.invoke(RemoteInvocationTraceInterceptor.java:77)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy56.createUser(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.remoting.support.RemoteInvocation.invoke(RemoteInvocation.java:205)
at org.springframework.remoting.support.DefaultRemoteInvocationExecutor.invoke(DefaultRemoteInvocationExecutor.java:38)
at org.springframework.remoting.support.RemoteInvocationBasedExporter.invoke(RemoteInvocationBasedExporter.java:78)
at org.springframework.remoting.support.RemoteInvocationBasedExporter.invokeAndCreateResult(RemoteInvocationBasedExporter.java:114)
at org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter.handleRequest(HttpInvokerServiceExporter.java:73)
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:49)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.voyager.utils.web.TimeStampFilter.doFilter(TimeStampFilter.java:64)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.voyager.utils.log4j.LoggerFilter.doFilter(LoggerFilter.java:127)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at com.voyager.utils.web.tomcat.FormAuthenticator.invoke(FormAuthenticator.java:123)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at com.voyager.utils.web.tomcat.VoyagerSingleSignOn.invoke(VoyagerSingleSignOn.java:178)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at org.springframework.remoting.support.RemoteInvocationUtils.fillInClientStackTraceIfPossible(RemoteInvocationUtils.java:47)
at org.springframework.remoting.support.RemoteInvocationResult.recreate(RemoteInvocationResult.java:115)
at org.springframework.remoting.support.RemoteInvocationBasedAccessor.recreateRemoteInvocationResult(RemoteInvocationBasedAccessor.java:85)
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.invoke(HttpInvokerClientInterceptor.java:148)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy20.createUser(Unknown Source)
at com.voyager.vip.actions.CampusUserEditAction.save(CampusUserEditAction.java:329)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:266)
at com.voyager.vip.actions.AbstractDispatchAction.execute(AbstractDispatchAction.java:261)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:113)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:413)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:225)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1858)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:459)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.voyager.utils.web.TimeStampFilter.doFilter(TimeStampFilter.java:64)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.voyager.utils.log4j.LoggerFilter.doFilter(LoggerFilter.java:138)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.voyager.utils.web.SessionDataSetupFilter.doFilter(SessionDataSetupFilter.java:104)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.voyager.utils.db.HibernateSessionFilter.doFilterUnsynchronized(HibernateSessionFilter.java:250)
at com.voyager.utils.db.HibernateSessionFilter.doFilter(HibernateSessionFilter.java:176)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)
at com.voyager.utils.web.tomcat.FormAuthenticator.invoke(FormAuthenticator.java:123)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at com.voyager.utils.web.tomcat.VoyagerSingleSignOn.invoke(VoyagerSingleSignOn.java:205)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

The transactionManager in the application I'm trying to save the user to goes like this:

<bean id="transactionManager"  
      class="org.springframework.orm.hibernate3.HibernateTransactionManager" 
      p:sessionFactory-ref="sessionFactory"/>

that is in services.xml. I have a remote-servlet.xml I've added for this service I'm accessing that contains this line:
<context:annotation-config/>

In the service implementation class I have at the top: @Autowired private ApplicationUserDao applicationUserDao;

The context:annotation-config allows it to autowire, without it(context:annotation-config) I no longer get the error above, I get a null exception because applicationUserDao is null. I am a beginner at spring and hibernate configuration. I'm not sure exactly how the other transactionManager is getting loaded to conflict with the one in services.xml. I don't know how to use applicationUserDao.save() with out auto wiring it. Any suggestions or information about how these are clashing would be great :)

editing to give solution: Thanks Manuel Jordan, I added <tx:annotation-driven/> to my remote-servlet.xml. I stuck with <context:annotation-config/> as well. Works perfect now :D

sef9110
  • 153
  • 2
  • 10
  • Be sure your Hibernate be 3 because your `TransactionManager` is working with the version 3. Be aware there is a `TransactionManager` for Hibernate **4**. Now how you are declaring your beans? specially your repository? Because `context:annotation-config` only resolves DI (`@Autowired` in this case) but does not scan any `@Repository`. Read carefully the following: http://stackoverflow.com/a/24083073/3665178 – Manuel Jordan Oct 17 '14 at 00:57
  • Once understood the previous comment, let me know about "spring remote service" how you are doing that. – Manuel Jordan Oct 17 '14 at 01:01
  • Thank you for the response. The application is definitely using hibernate 3. We are not using hibernate 4 at this time. ApplicationUserDao has an @Repository annotation above its declaration. So, if I am understanding your post, context:annotation-config will not resolve it but, annotation:component-scan will. I will try annotation:component-scan and get back to you.. – sef9110 Oct 17 '14 at 01:21
  • Using annotation:component-scan gives the same error as above. I am doing the spring remote service by using this method [link](http://www.javaworld.com/article/2072246/simple-spring-http-remoting-example.html). I have debugged it into the remote service so I know all my data is reaching it properly. Just somehow, I have messed up the transaction or hibernate configuration – sef9110 Oct 17 '14 at 01:31
  • I would ask for update your original post and share how you are sending/calling and receiving/processing the data. – Manuel Jordan Oct 17 '14 at 01:40
  • 01) Is that the complete error stack trace?. 02) Be more explicit about in what moment the error arises 03) When the web-server starts, is there any error in the console? – Manuel Jordan Oct 17 '14 at 01:41
  • I've updated to add the full stack trace. The error arises on line systemUserDao.save( su ); in the implementation class. There are no errors when the server starts. Thank you for your help. – sef9110 Oct 17 '14 at 01:56
  • 01) Post source code for `SystemUserDao` 02) if `applicationUser` is a class, the naming convention is wrong, must be `ApplicationUser` 03) Why create `ApplicationUser` and copy all the data from `ElibraryUser` 04) your `createUser` method should return an `ApplicationUser`, not a boolean, if arise an exception, the method never returns a `false` – Manuel Jordan Oct 17 '14 at 12:37
  • Be sure you have `` in your code too. – Manuel Jordan Oct 17 '14 at 12:43
  • Thanks a lot, that was it, I edited the original post to include the solution. :) – sef9110 Oct 17 '14 at 15:16
  • If my other reply in the other URL was useful, you can give a check too – Manuel Jordan Oct 17 '14 at 16:52

2 Answers2

0

HibernateTransactionManager only works for resource local transactions, where you have one non-XA DataSource only.

Your exception tell you that you want to use JTA instead. So either your DataSource is XA and retrieved from an application server JNDI, or you have miss-configured some of the following Hibernate properties:

Instead of

 hibernate.transaction.factory_class=JDBCTransactionFactory

you might have set:

 hibernate.transaction.factory_class=JTATransactionFactory

Or you might have set:

hibernate.transaction.manager_lookup_class

But that's not required for resource local Tx.


Or you might have set:

hibernate.current_session_context_class=jta

But that's also not required for resource local Tx when using Spring.

Community
  • 1
  • 1
Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
0

Be sure your Hibernate be 3 because your TransactionManager is working with the version 3. Be aware there is a TransactionManager for Hibernate 4. Now how you are declaring your beans? specially your repository? Because context:annotation-config only resolves DI (@Autowired in this case) but does not scan any @Repository. Read carefully the following:

Difference between <context:annotation-config> vs <context:component-scan>

And the most important Be sure you have <tx:annotation-driven/> in your code too. Consider that element how a switch to indicate Spring, turn on all the transaction features. With that @Transactional together with the transactionManager work how is expected

Community
  • 1
  • 1
Manuel Jordan
  • 15,253
  • 21
  • 95
  • 158