Question
I'm using OpenJPA and want to configure it to use Autocommit on 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 be able to do is this:
MyEntity e = new MyEntity();
em.persist(e); // auto commit here
I have this property set to true:
openjpa.NontransactionalWrite : true
Any clues?!
Solution
You can't auto-commit with JPA. If you want to remove the local transaction management, use JTA/CMT or Spring managed transactions.
OTHER TIPS
As far as I know, OpenJPA uses the autocommit value from the underlying connection. BUT it explicitly sets autocommit to false whenever you begin a transaction.
You can check the underlying connection with the following code:
OpenJPAEntityManager oem = OpenJPAPersistence.cast(em);
Connection conn = (Connection) oem.getConnection();
boolean autoCommit = conn.getAutoCommit();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow