Tuesday 27 March 2012

Transaction marked as rollbackOnly

This exception is exceptionally frustrating: 

org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:476)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy75.call(Unknown Source)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller$1.run(AbstractPollingEndpoint.java:207)
    at org.springframework.integration.util.ErrorHandlingTaskExecutor$1.run(ErrorHandlingTaskExecutor.java:52)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: javax.persistence.RollbackException: Transaction marked as rollbackOnly
    at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:73)
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:467)
    ... 12 more


 ....of course you want to know what set the rollbackOnly flag and why.  Here's one way of finding out:
  1. Attach to application with debugger (e.g. Debug Tomcat)
  2. Assuming Hibernate is the underlying implementation, break on the setRollbackOnly() method in org.hibernate.ejb.TransactionImpl (Eclipse tip: use Ctrl+Shift+T to search for a class)
  3. when the debugger breaks on this method you can bubble up the call stack in the debugger and usually find out what caused this transaction to be marked as rollbackOnly.
Thanks to Useful Code Snippets blog:  But why was my transaction marked as rollbackOnly?

Wednesday 21 March 2012

O2 Mobile Broadband (UK)

A SIM with no instructions and it's a little tricky to figure out how to connect to O2 Pay & Go mobile broadband.  These settings worked for me:

APNm-bb.o2.co.uk
Usernameo2bb
Passwordpassword
Number*99#
AuthenticationPAP

Then go to https://mobilebroadbandaccess.o2.co.uk to check your balance, top-up, etc.  I assumed I had to create a "My O2" mobile account, but that doesn't appear to work with mobile broadband.