Announcement Announcement Module
Collapse
No announcement yet.
Problem with @Transactional annotation with blazeDS and Hibernate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with @Transactional annotation with blazeDS and Hibernate

    I have integrated blazeds, spring, and hibernate, using the standard spring-hibernate integration, and the new Spring-BlazeDS integration. However I am unable to get the @transactional annotation to work correctly on my remote-destinations.

    Here is what my config looks like:

    Code:
    	<flex:message-broker>
    		<flex:secured />
    	</flex:message-broker>
    	
      	<tx:annotation-driven transaction-manager="myTxManager"/>
    	
    	<bean id="clientServiceImpl" class="com.mine.ClientDelegate">
    		<constructor-arg ref="hibernateDAOFactory" />
    		<security:intercept-methods>
    			<security:protect method="*" access="ROLE_USER" />
    		</security:intercept-methods>
    	</bean>
    	
    	<flex:remoting-destination ref="clientServiceImpl"/>
    
    	<bean id="myTxManager"
    		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory" ref="sessionFactory" />
    	</bean>	
    
      ... and the various other beans such as the sessionFactory, datasource, etc ...
    However, if I try to use @Transactional with the ClientDelegate class, it isn't recognized and I get an exception that a session doesn't exist and can't be created based on the configuration. Here is a snippet of that code:

    Code:
    import org.springframework.transaction.annotation.Transactional;
    
    @Transactional
    public class ClientDelegate implements IClientDelegate {
    However, if I don't use annotations, and I use the TransactionProxyFactoryBean like shown below, it works fine:
    Code:
    	<bean id="clientServiceImpl" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="transactionManager" ref="myTxManager"/>	
    		<property name="proxyInterfaces" value="com.mine.IClientDelegate" />
    		<property name="target">
    			<bean class="com.mine.ClientDelegate">
    				<constructor-arg ref="hibernateDAOFactory" />
    			</bean>
    		</property>
    		<property name="transactionAttributes">
    			<props>
    				<prop key="*">PROPAGATION_REQUIRED</prop>
    			</props>
    		</property>		
    		<flex:remoting-destination />
    		<security:intercept-methods>
    			<security:protect method="*" access="ROLE_USER" />
    		</security:intercept-methods>		
    	</bean>
    I've also been able to successfully use the @Transactional with a DAO which is not configured as a remoting-destination.

    Is there something in the way the new flex/blazeds integration is coded that prevents the use of @Transactional for remoting-destination's?

    Thanks.
    - David.

  • #2
    stack trace? spring debug log output?

    Blazeds integration does not interfere with the @Transactional annotation. I have mine working just the same as yours.


    Did you remember to tell spring to look for the annotations using

    Code:
    <context:annotation-config/>
    Last edited by kochcp; May 26th, 2009, 06:50 PM.

    Comment


    • #3
      whoops, I meant this declaration

      Code:
      <tx:annotation-driven transaction-manager="transactionManager"/>

      Comment


      • #4
        Here is the relevant part of the logging (with the exception stack) :

        Code:
        09-05-29 10:48:12:093 [http-8080-3] INFO  servlet.MessageBrokerHandlerAdapter: Channel endpoint my-amf received request.
        09-05-29 10:48:12:140 [http-8080-3] DEBUG method.AbstractFallbackMethodDefinitionSource: Adding security method [CacheKey[com.pgi.applications.premierepeople.business.ClientDelegate; public abstract com.pgi.applications.premierepeople.vo.UserVO com.pgi.applications.premierepeople.business.IClientDelegate.getUser(java.lang.String,java.lang.String) throws java.lang.Exception]] with attribute [[ROLE_USER]]
        09-05-29 10:48:12:144 [http-8080-3] DEBUG intercept.AbstractSecurityInterceptor: Secure object: ReflectiveMethodInvocation: public abstract com.pgi.applications.premierepeople.vo.UserVO com.pgi.applications.premierepeople.business.IClientDelegate.getUser(java.lang.String,java.lang.String) throws java.lang.Exception; target is of class [com.pgi.applications.premierepeople.business.ClientDelegate]; ConfigAttributes: [ROLE_USER]
        09-05-29 10:48:12:148 [http-8080-3] DEBUG intercept.AbstractSecurityInterceptor: Previously Authenticated: org.springframework.security.providers.UsernamePasswordAuthenticationToken@9849789d: Principal: org.springframework.security.userdetails.User@ed9d7500: Username: manager; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_USER; Password: [PROTECTED]; Authenticated: true; Details: null; Granted Authorities: ROLE_USER
        09-05-29 10:48:12:153 [http-8080-3] DEBUG intercept.AbstractSecurityInterceptor: Authorization successful
        09-05-29 10:48:12:154 [http-8080-3] DEBUG support.XmlWebApplicationContext: Publishing event in context [[email protected]1f7e273]: org.springframework.security.event.authorization.AuthorizedEvent[source=ReflectiveMethodInvocation: public abstract com.pgi.applications.premierepeople.vo.UserVO com.pgi.applications.premierepeople.business.IClientDelegate.getUser(java.lang.String,java.lang.String) throws java.lang.Exception; target is of class [com.pgi.applications.premierepeople.business.ClientDelegate]]
        09-05-29 10:48:12:156 [http-8080-3] DEBUG intercept.AbstractSecurityInterceptor: RunAsManager did not change Authentication object
        09-05-29 10:48:12:157 [http-8080-3] DEBUG support.DefaultListableBeanFactory: Returning cached instance of singleton bean 'userDAO'
        09-05-29 10:48:12:158 [http-8080-3] DEBUG hibernate3.SessionFactoryUtils: Opening Hibernate Session
        09-05-29 10:48:12:269 [http-8080-3] DEBUG hibernate3.SessionFactoryUtils: Closing Hibernate Session
        09-05-29 10:48:12:282 [http-8080-3] ERROR business.ClientDelegate: Unable to load user
        org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
        	at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
        	at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:544)
        	at com.pgi.applications.premierepeople.dao.GenericHibernateDAO.getSession(GenericHibernateDAO.java:44)
        	at com.pgi.applications.premierepeople.dao.hibernate.UserDAOHibernate.findByCredentials(UserDAOHibernate.java:19)
        	at com.pgi.applications.premierepeople.business.ClientDelegate.getUser(ClientDelegate.java:74)
        	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        	at java.lang.reflect.Method.invoke(Method.java:597)
        	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
        	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
        	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
        	at org.springframework.security.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:66)
        	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        	at $Proxy5.getUser(Unknown Source)
        	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        	at java.lang.reflect.Method.invoke(Method.java:597)
        	at flex.messaging.services.remoting.adapters.JavaAdapter.invoke(JavaAdapter.java:406)
        	at flex.messaging.services.RemotingService.serviceMessage(RemotingService.java:183)
        	at flex.messaging.MessageBroker.routeMessageToService(MessageBroker.java:1417)
        	at flex.messaging.endpoints.AbstractEndpoint.serviceMessage(AbstractEndpoint.java:878)
        	at flex.messaging.endpoints.AbstractEndpoint$$FastClassByCGLIB$$1a3ef066.invoke(<generated>)
        	at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
        	at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
        	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
        	at org.springframework.flex.core.MessageInterceptionAdvice.invoke(MessageInterceptionAdvice.java:59)
        	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        	at org.springframework.aop.framework.adapter.ThrowsAdviceInterceptor.invoke(ThrowsAdviceInterceptor.java:126)
        	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        	at org.springframework.aop.framework.Cglib2AopProxy$FixedChainStaticTargetInterceptor.intercept(Cglib2AopProxy.java:582)
        	at flex.messaging.endpoints.AMFEndpoint$$EnhancerByCGLIB$$a0b40edb.serviceMessage(<generated>)
        	at flex.messaging.endpoints.amf.MessageBrokerFilter.invoke(MessageBrokerFilter.java:121)
        	at flex.messaging.endpoints.amf.LegacyFilter.invoke(LegacyFilter.java:158)
        	at flex.messaging.endpoints.amf.SessionFilter.invoke(SessionFilter.java:49)
        	at flex.messaging.endpoints.amf.BatchProcessFilter.invoke(BatchProcessFilter.java:67)
        	at flex.messaging.endpoints.amf.SerializationFilter.invoke(SerializationFilter.java:146)
        	at flex.messaging.endpoints.BaseHTTPEndpoint.service(BaseHTTPEndpoint.java:274)
        	at flex.messaging.endpoints.AMFEndpoint$$EnhancerByCGLIB$$a0b40edb.service(<generated>)
        	at org.springframework.flex.servlet.MessageBrokerHandlerAdapter.handle(MessageBrokerHandlerAdapter.java:101)
        	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
        	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
        	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
        	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
        	at org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
        	at org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
        	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
        	at org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101)
        	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
        	at org.springframework.security.providers.anonymous.AnonymousProcessingFilter.doFilterHttp(AnonymousProcessingFilter.java:105)
        	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
        	at org.springframework.security.ui.rememberme.RememberMeProcessingFilter.doFilterHttp(RememberMeProcessingFilter.java:116)
        	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
        	at org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareRequestFilter.java:91)
        	at 
        etc...
        Notice that it appears to have opened and closed a hibernate session right before the call into the client delegate. Again, I can use annotations on other objects with my current configuration (which means I have all the necessary jar files and such), but I can't on the clientDelegate. I presume this is because of either the security portions of the bean, or the flex portions.

        As for the "annotation-driven" tag, you can see that I do include that from my original post.

        Comment


        • #5
          same issue

          Hey davideanderson, Im facing exactly the same issue while trying to use annotations vs proxy beans. Did you find a workaround? Thanks!

          Comment

          Working...
          X