Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-1803

Unwrap EntityManager to Connection

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.1
    • 2.2.0
    • competitive, jpa
    • None

    Description

      This is currently the recommended way to access the javax.sql.Connection underlying an EntityManager:

      OpenJPAEntityManager oem = OpenJPAPersistence.cast(em);
      Connection con = (Connection) oem.getConnection();

      It would be more convenient to simply write

      Connection con = em.unwrap(Connection.class);

      That way, the client needing to access the Connection only depends on the javax.persistence API and not on org.apache.openjpa.*.

      I believe the JPA 2.0 spec neither mandates nor forbids this functionality. It is supported by Eclipselink 2.x.

      Attachments

        1. OPENJPA-1803.patch
          2 kB
          Sebastian Laskawiec

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            curtisr7 Richard G. Curtis
            hwellmann Harald Wellmann
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment