Another Transaction problem
With Hibernate CR1, Hibernate EM CR2, Spring RC2, Spring Webflow 1.0 RC3
and OpenEntityManagerInView filter
I'm using the JpaTransactionManager and we've been using it for awhile without problems and there is also tests written against it to test it's configured correctly.
I've a business method declared with a TX Required attribute rollback on any Exception, which performs a couple of deletes using a DAO which in turn uses the JpaTemplate.Code: Role role = findRole(roleId); Listlt;Workflowgt; workflows = roleDAO.findWorkFlowsByRole(role.getId()); for(Workflow workflow : workflows) {roleDAO.delete(workflow); }
Listlt;DomainObjectgt; domainObjects = roleDAO.findDomainObjects(role.getId()); for(DomainObject domainObject : domainObjects) {roleDAO.delete(domainObject); } roleDAO.removeReferencesFromMembers(role.getId()); roleDAO.delete(role);
where the removeReferencesFromMembers is executing a batch update which fails with an Exception
The calling method in the SWF action looks like this
Code:
public Event delete(RequestContext requestContext) throws Exception { try {RoleForm form = (RoleForm) getFormObject(requestContext);roleService.deleteRole(form.getRoleId()); } catch(Exception e) {return error(); } return success(); }
Upon an Exception the SWF will transit upon the quot;errorquot; event to another action which looks like thisCode: public Event setupForm(RequestContext requestContext) throws Exception { Long id = getInitValueId(requestContext); if(id != null) {RoleForm form = (RoleForm) getFormObject(requestContext);form.setRole(roleService.findRole(id));return success(); } return error(); }
As the transition occurs in the same Request and I'm using the OEMIV filter the EM will be the same in both actions.
If the call to the deleteRole method fails I expected the changes to get rollbacked and if I check the database I could not see any changes so far so good. But as soon as the findRole method is executed in the setupForm() method the changes occur in the database, ie. the deletion of the dependent objects are commited.
I just can't figure out if this is really a bug or if I'm missing something.Here's the configuration of the transaction attributes
Code:
lt;bean id=quot;roleService_quot; class=quot;biz.ist.atlas.domain.role.service.RoleServiceImplquot; autowire=quot;byNamequot;/gt;
lt;bean id=quot;roleServicequot; parent=quot;serviceProxyTemplatequot;gt;
lt;property name=quot;proxyInterfacesquot; value=quot;biz.ist.atlas.domain.role.service.RoleServicequot;/gt;
lt;property name=quot;targetquot; ref=quot;roleService_quot;/gt;
lt;property name=quot;transactionAttributesquot;gt;
lt;propsgt;
lt;prop key=quot;find*quot;gt ROPAGATION_SUPPORTS,-Exceptionlt;/propgt;
lt;prop key=quot;delete*quot;gt ROPAGATION_REQUIRED,-Exceptionlt;/propgt;
lt;prop key=quot;save*quot;gt ROPAGATION_REQUIRED,-Exceptionlt;/propgt;
lt;prop key=quot;create*quot;gt ROPAGATION_REQUIRED,-Exceptionlt;/propgt;
lt;prop key=quot;update*quot;gt ROPAGATION_REQUIRED,-Exceptionlt;/propgt;
lt;prop key=quot;reorder*quot;gt ROPAGATION_REQUIRED,-Exceptionlt;/propgt;
lt;/propsgt;
lt;/propertygt;
lt;/beangt; |