2
votes

I'm having a strange problem with my transactions not committing in spring. After profiling the database it looks like spring is committing the transaction before it starts?

Here is what I am seeing the the profiler..

SQL:BatchStarting   select 1  
SQL:BatchCompleted  select 1  
SQL:BatchStarting   IF @@TRANCOUNT > 0 COMMIT TRAN  
SQL:BatchCompleted  IF @@TRANCOUNT > 0 COMMIT TRAN      
RPC:Completed   exec vbosv_DLLVersion_Update 77,N'15',NULL,N'12.2.2.1',N'12.2.3.4'

The transaction is not committed in this case but if i run a piece of code after this that calls the database again it will commit the previous transaction. I think that it is committing then because it starts with IF @@TRANCOUNT > 0 COMMIT TRAN.

I used declarative transaction management and here are some of my configs

<!-- Transactional Advice -->
<tx:advice id="txAdvice" transaction-manager="txManager">
   <tx:attributes>
    <tx:method name="process*" rollback-for="Throwable"/>
    <tx:method name="write*" rollback-for="Throwable"/>
    <tx:method name="upload*" rollback-for="Throwable"/>
    <tx:method name="store*" rollback-for="Throwable"/>
   </tx:attributes>
</tx:advice>
<aop:config>
   <aop:pointcut id="dataServicesOperation" expression="execution(* com.enterprise.dataservices.DataServicesImpl.*(..))"/>
   <aop:advisor advice-ref="txAdvice" pointcut-ref="dataServicesOperation"/>
</aop:config>

I'm a spring newbie and sort of lost on whats happening here. Thanks ahead for and help!

1
What exactly leads you to believe that a transaction has not been committed? Have you validated that there is indeed an open transaction on the database server? - John Sansom
It seems to be rolling back actually. I know i am in a transaction because when i debug and step into the method that is supposed to be in a transaction i cannot select from the database. When the method completes i can then select but there is not data inserted into the db. If i copy the exact exec command that profile is logging "exec vbosv_DLLVersion_Update 77,N'15',NULL,N'12.2.2.1',N'12.2.3.4'" it will successfully update the database. For some reason my application cannot commit these updates to the db. - Braden
I am running all of this from a junit test. This test is the last test in the file. If i move this test to be the second to last test the data is successfully committed to the database. - Braden

1 Answers

2
votes

Do you have @Rollback(false) on junit test method?