openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daryl Stultz <daryl.stu...@opentempo.com>
Subject JDBC operation in JPA transaction
Date Thu, 15 Sep 2011 20:00:04 GMT
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.

-- 
Daryl Stultz
_____________________________________
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
http://www.opentempo.com
mailto:daryl.stultz@opentempo.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message