You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Sebastian Laskawiec (JIRA)" <ji...@apache.org> on 2011/06/21 15:33:47 UTC
[jira] [Updated] (OPENJPA-1803) Unwrap EntityManager to Connection
[ https://issues.apache.org/jira/browse/OPENJPA-1803?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Sebastian Laskawiec updated OPENJPA-1803:
-----------------------------------------
Attachment: OPENJPA-1803.patch
Hi, I also think it is a good idea. I think it is OK with the spec to return here java.sql.Connection:
/**
* Return an object of the specified type to allow access to the
* provider-specific API. If the provider's EntityManager
* implementation does not support the specified class, the
* PersistenceException is thrown.
…
I found also part of the documentation, which describes, how to obtain JDBC connection: http://openjpa.apache.org/builds/1.0.1/apache-openjpa-1.0.1/docs/manual/ref_guide_dbsetup_sqlconn.html
Please take a look at this patch, I added _broker.getConnection() to EntityManagerImpl.unwrap method and added one test.
> Unwrap EntityManager to Connection
> ----------------------------------
>
> Key: OPENJPA-1803
> URL: https://issues.apache.org/jira/browse/OPENJPA-1803
> Project: OpenJPA
> Issue Type: Improvement
> Components: competitive, jpa
> Affects Versions: 2.0.1
> Reporter: Harald Wellmann
> Attachments: OPENJPA-1803.patch
>
>
> 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.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira