title: Combining JPA and JDBC actions in one transaction
body: <p>So, I have an application with some legacy JDBC calls in it that I need to update with some additional JPA actions.  I need to be able to make both JDBC calls and JPA calls as part of the same DB transaction.  I'm using OpenJPA 2.1.1 and Postgres 9.1, if it matters.  The following code appears to work correctly - I've run some basic tests, and both the JDBC and JPA statements execute; an error in either one results in the pair of statements not happening (e.g. they're part of the same DB transaction).  Are there any problems with it that I'm not seeing - some best practice that I'm violating, or some other reason I can't re-use the Connection object in this manner?</p>
  
  <pre><code>EntityManager em = _em; //acquired from OpenJPA
  em.getTransaction().begin();
  Connection conn;
  try {
    OpenJPAEntityManager oem = (OpenJPAEntityManager) em.getDelegate();
    conn = oem.getConnection();
    PreparedStatement ps = conn.prepareStatement(myStatement);
    //initialize parameters in ps
    ps.executeUpdate();
    em.merge(myJpaObject);
    em.getTransaction().commit();
  } finally {
      if (ps != null &amp;&amp; !ps.isClosed()) {
        ps.close();
      }
      if (em.getTransaction().isActive()) {
      em.getTransaction().rollback();
    }
  }
  </code></pre>
  
  <p>Thanks!</p>