I'm trying to migrate from the old 1.2.x style to the 2.0 XSD style. Here's what I have in 1.2.8:
Using 2.0, I'm guessing this same advice is applied using the following:Code:<!-- Transaction template for Managers, from: http://blog.exis.com/colin/archives/2004/07/31/concise-transaction-definitions-spring-11/ --> <bean id="txProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager" ref="transactionManager"/> <property name="transactionAttributes"> <props> <prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="remove*">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property> </bean> <!-- Generic manager that can be used to do basic CRUD operations on any objects --> <bean id="manager" parent="txProxyTemplate"> <property name="target"> <bean class="org.appfuse.service.impl.BaseManager"> <property name="dao" ref="dao"/> </bean> </property> </bean> <!-- Transaction declarations for business services. To apply a generic transaction proxy to all managers, you might look into using the BeanNameAutoProxyCreator --> <bean id="userManager" parent="txProxyTemplate"> <property name="target"> <bean class="org.appfuse.service.impl.UserManagerImpl"> <property name="userDao" ref="userDao"/> </bean> </property> <!-- Override default transaction attributes b/c of UserExistsException --> <property name="transactionAttributes"> <props> <prop key="save*">PROPAGATION_REQUIRED,-UserExistsException</prop> <prop key="remove*">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property> <!-- This property is overriden in applicationContext-security.xml to add method-level role security --> <property name="preInterceptors"> <list> <ref bean="userSecurityInterceptor"/> </list> </property> </bean> <!-- This interceptor insures that that users can only update themselves, not other users --> <bean id="userSecurityInterceptor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor"> <property name="advice" ref="userSecurityAdvice"/> <property name="patterns" value=".*saveUser"/> </bean> <bean id="userSecurityAdvice" class="org.appfuse.service.UserSecurityAdvice"> <property name="userCache" ref="userCache"/> </bean>
I'd like to say this works, but it doesn't. I get tests that fail because I'm calling save() in a read-only transaction. I'm using Spring 2.0-rc1. I tried using rc2 (the latest version in ibiblio) and everything blows up when initializing.Code:<aop:config> <aop:advisor id="serviceMethods" pointcut="execution(* *.service.*Manager.*(..))" advice-ref="txAdvice"/> <aop:advisor id="userManagerMethods" pointcut="execution(* *.service.UserManager.*(..))" advice-ref="userManagerTxAdvice"/> <aop:advisor id="userManagerSecurity" pointcut="execution(* *.service.UserManager.saveUser(..))" advice-ref="userSecurityAdvice"/> </aop:config> <tx:advice id="txAdvice"> <tx:attributes> <tx:method name="*"/> </tx:attributes> </tx:advice> <tx:advice id="userManagerTxAdvice"> <tx:attributes> <tx:method name="save*" rollback-for="UserExistsException"/> <tx:method name="remove*"/> <tx:method name="*" read-only="true"/> </tx:attributes> </tx:advice> <!-- Generic manager that can be used to do basic CRUD operations on any objects --> <bean id="manager" class="org.appfuse.service.impl.BaseManager"> <property name="dao" ref="dao"/> </bean> <bean id="userManager" class="org.appfuse.service.impl.UserManagerImpl"> <property name="userDao" ref="userDao"/> </bean> <bean id="userSecurityAdvice" class="org.appfuse.service.UserSecurityAdvice"> <property name="userCache" ref="userCache"/> </bean>
I thought removing the read-only flag from userManagerTxAdvice would work, but no dice, the issue still happens.
Stack trace:Code:<tx:advice id="userManagerTxAdvice"> <tx:attributes> <tx:method name="save*" rollback-for="UserExistsException"/> <tx:method name="remove*"/> <tx:method name="*"/> </tx:attributes> </tx:advice>
Code:[INFO] [talledLocalContainer] Caused by: javax.faces.el.EvaluationException: Exception while invokin g expression #{signupForm.save} [INFO] [talledLocalContainer] at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl. java:153) [INFO] [talledLocalContainer] at org.apache.myfaces.application.ActionListenerImpl.processAction(A ctionListenerImpl.java:63) [INFO] [talledLocalContainer] ... 78 more [INFO] [talledLocalContainer] Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into Flush Mode.AUTO or remove 'readOnly' marker from transaction definition [INFO] [talledLocalContainer] at org.springframework.orm.hibernate3.HibernateTemplate.checkWriteOp erationAllowed(HibernateTemplate.java:1082)


Reply With Quote