Only commit/rollback if transaction is active

This change only commits transaction if is active. 

And regarding the docs, <code>EntityManager.getTransaction()</code> never returns <code>null</code>, so I remove this condition.