When I execute the code, its showing org.springframework.transaction.UnexpectedRollbackException Transaction rolled back because it has been marked as rollback-only. But its not rolling back.
My Code:
Service level
public void checkTransaction(Users user) throws Exception {
adminDao.insertUser(user);
System.out.println("Transaction active :: " + TransactionSynchronizationManager.isActualTransactionActive());
throw (new Exception("Testing Transaction"));
}
xml
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="*" propagation="REQUIRED" rollback-for="Exception" />
</tx:attributes>
</tx:advice>
<tx:annotation-driven proxy-target-class="true"
transaction-manager="transactionManager" />
<aop:config>
<aop:pointcut id="serviceOperation"
expression="execution(* myapp.admin.service.AdminService.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
</aop:config>
POJO
My POJO (Users) Bean is not a annotated one, its mapped to hbm file. But it is registered in mapping resources.
<bean id="mysessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>myapp/admin/vo/Users.hbm.xml</value></list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
rollback-for="java.lang.Exception"maybe? - mspadminDao.insertUser(user)method. Check if its working. - Abdullah Khan