I think transaction is not kicking in atall. I can provide other files if required.
On console it inserts the data and throws the exception but no rollback.
Boot.java
context.xmlCode:public class Boot { public static void main(final String[] args) throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml", Boot.class); FooService fooService = (FooService) ctx.getBean("fooService"); Testemployee testemployee = new Testemployee(); testemployee.setEmployeename("someName"); fooService.insertFoo (testemployee); } }
FooServiceImpl.javaCode:<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://x.x.x.x:3306/db" /> <property name="username" value="un" /> <property name="password" value="pwd" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"><ref local="dataSource" /></property> <property name="configLocation"> <value> classpath:resources/hibernate/hibernate.cfg.xml </value> </property> </bean> <bean id="PersistenceFacade" class="com.x.x.persistence.PersistenceFacadeImpl"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="FacadeLookup" class="com.x.x.service.FacadeLookup"> <property name="persistenceFacade" ref="PersistenceFacade" /> </bean> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="fooService" class="com.x.x.admin.service.FooServiceImpl"> <property name="facadeLookup" ref="FacadeLookup"></property> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="insertFoo" rollback-for="Exception"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="fooServiceOperation" expression="execution(* com.x.x.admin.service.*.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceOperation"/> </aop:config>
Cross post : http://www.coderanch.com/t/526343/Sp...k-case#2386514Code:public class FooServiceImpl implements FooService { FacadeLookup facadeLookup; public void insertFoo(Testemployee testemployee) throws Exception { facadeLookup.getPersistenceFacade().save(testemployee); throw new Exception(); } public void setFacadeLookup(FacadeLookup facadeLookup) { this.facadeLookup = facadeLookup; } }



Reply With Quote
