Return-Path: X-Original-To: apmail-openjpa-users-archive@minotaur.apache.org Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C43FE87CA for ; Thu, 15 Sep 2011 20:00:32 +0000 (UTC) Received: (qmail 13802 invoked by uid 500); 15 Sep 2011 20:00:32 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 13770 invoked by uid 500); 15 Sep 2011 20:00:32 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 13759 invoked by uid 99); 15 Sep 2011 20:00:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Sep 2011 20:00:32 +0000 X-ASF-Spam-Status: No, hits=0.6 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_MED,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [64.18.2.26] (HELO exprod7og124.obsmtp.com) (64.18.2.26) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 15 Sep 2011 20:00:26 +0000 Received: from mail-gw0-f48.google.com ([74.125.83.48]) (using TLSv1) by exprod7ob124.postini.com ([64.18.6.12]) with SMTP ID DSNKTnJZRMYp6Nl5tq5YvvYAi7oS4wtL29u2@postini.com; Thu, 15 Sep 2011 13:00:06 PDT Received: by mail-gw0-f48.google.com with SMTP id 22so3150445gwj.7 for ; Thu, 15 Sep 2011 13:00:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.68.60.9 with SMTP id d9mr2510608pbr.159.1316116804445; Thu, 15 Sep 2011 13:00:04 -0700 (PDT) Received: by 10.142.216.15 with HTTP; Thu, 15 Sep 2011 13:00:04 -0700 (PDT) Date: Thu, 15 Sep 2011 16:00:04 -0400 Message-ID: Subject: JDBC operation in JPA transaction From: Daryl Stultz To: OpenJPA User List Content-Type: multipart/alternative; boundary=bcaec52e57c79ca9cf04ad00523d --bcaec52e57c79ca9cf04ad00523d Content-Type: text/plain; charset=ISO-8859-1 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 --bcaec52e57c79ca9cf04ad00523d--