Autocommit OpenJPA writes

I am using OpenJPA and want to configure it to use Autocommit with every write / insert operation.

At the moment, I have to do this:

MyEntity e = new MyEntity(); em.getTransaction().begin(); em.persist(e); em.getTransaction().commit(); 

What I want to do is:

 MyEntity e = new MyEntity(); em.persist(e); // auto commit here 

I have this property set to true:

 openjpa.NontransactionalWrite : true 

Any clues ?!

+4
source share
2 answers

You cannot auto commit using JPA. If you want to remove local transaction management, use JTA / CMT or Spring Managed Transactions.

+4
source

As far as I know, OpenJPA uses the autocommit value from the base connection. BUT it explicitly sets autocommit to false when you start a transaction.

You can check the basic connection with the following code:

 OpenJPAEntityManager oem = OpenJPAPersistence.cast(em); Connection conn = (Connection) oem.getConnection(); boolean autoCommit = conn.getAutoCommit(); 
+1
source

All Articles