Hi Daryl,

Try closing the connection:

connection.executeUpdate(...);
connection.close();

Without closing, I suspect the entity manager and your JDBC update operate on 
different connections.

The openjpa.ConnectionRetainMode property may also have some impact here.

Greetings,
Milosz


> Hello,
> 
> consider the following code in an entity "save" method:
> 
> em.getTransaction().begin();
> try {
> // get a hold of JDBC connection so we can join transaction
> OpenJPAEntityManager emo = (OpenJPAEntityManager) em;
> Connection connection = (Connection) emo.getConnection();
> // ... do JDBC insert
> connection.executeUpdate(...);
> em.merge(this);
> em.getTransaction().commit();
> } catch (...) {
> }
> 
> The idea is to start a transaction on the EM, perform an operation in JDBC,
> then commit the EM transaction. When the commit fails the JDBC operation is
> successful. I expected the rollback of the transaction to rollback the
> operation on the JDBC connection, too. Am I doing this right? How can I
> perform a JDBC operation in a JPA transaction and have it rolled back upon
> failure of commit?
> 
> Thanks.
> 
> 

Reply via email to