I'm using JPA Toplink-essential and developing RESTful web app.
Here is one thing to mention first.
Not using JTA
So my persistences.xml is defined not to use JTA.
<persistence-unit name="kojoPU">
<provider>oracle.toplink.essentials.PersistenceProvider</provider>
<non-jta-data-source>machinePrototype</non-jta-data-source>
This allows the entity manager not to execute query immediately with executeUpdate() It will wait til commit.
em.getTransaciton().begin();
Query query = em.createNativeQuery("DELETE FROM table1 WHERE theId = 10;");
query.executeUpdate(); //not yet executed until transaction is commited.
//continue do something...
em.getTransaction().commit(); //the query above is executed here finally
But there is one big problem, after transaction.begin(), is there is any error like JSONException
or indexOutOfBoundsException
, the transaction is not closed and kept open for a while.
Is it possible to force close the transaction somehow in such case?