You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Chris Wolf (JIRA)" <ji...@apache.org> on 2013/06/06 23:08:22 UTC
[jira] [Comment Edited] (OPENJPA-2393) Can only get
java.sql.Connection from EMF's DataSource in container-managed env.
[ https://issues.apache.org/jira/browse/OPENJPA-2393?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13677510#comment-13677510 ]
Chris Wolf edited comment on OPENJPA-2393 at 6/6/13 9:08 PM:
-------------------------------------------------------------
My workaround is as follows:
OpenJPAEntityManagerFactorySPI spiEmf = (OpenJPAEntityManagerFactorySPI)
OpenJPAPersistence.cast(emf);
OpenJPAConfiguration conf = spiEmf.getConfiguration();
// no good - they obfuscate the password...
//Map<String, Object> props = conf.toProperties(true);
Map<String, String> props = null;
if (conf instanceof ConfigurationImpl) {
// getFieldValue uses reflection in context of PrivilegedAction to override "private" field and grab "ConfigurationImpl._props" field.
// Could we please get a public accessor? ********
props = ObjectUtil.getFieldValue(conf, "_props");
}
DataSource dataSource = (DataSource) conf.getConnectionFactory();
// only works in managed env.
//conn = dataSource.getConnection();
conn = dataSource.getConnection(props.get("openjpa.ConnectionUserName"),
props.get("openjpa.ConnectionPassword"));
was (Author: cw10025@gmail.com):
My workaround is as follows:
OpenJPAEntityManagerFactorySPI spiEmf = (OpenJPAEntityManagerFactorySPI)
OpenJPAPersistence.cast(emf);
OpenJPAConfiguration conf = spiEmf.getConfiguration();
// no good - they obfuscate the password...
//Map<String, Object> props = conf.toProperties(true);
Map<String, String> props = null;
if (conf instanceof ConfigurationImpl) {
// getFieldValue uses reflection in context of PrivilegedAction to override "private" field an grab "ConfigurationImpl._props" field.
// Could we please get a public accessor? ********
props = ObjectUtil.getFieldValue(conf, "_props");
}
DataSource dataSource = (DataSource) conf.getConnectionFactory();
// only works in managed env.
//conn = dataSource.getConnection();
conn = dataSource.getConnection(props.get("openjpa.ConnectionUserName"),
props.get("openjpa.ConnectionPassword"));
> Can only get java.sql.Connection from EMF's DataSource in container-managed env.
> --------------------------------------------------------------------------------
>
> Key: OPENJPA-2393
> URL: https://issues.apache.org/jira/browse/OPENJPA-2393
> Project: OpenJPA
> Issue Type: Bug
> Components: jpa
> Affects Versions: 2.2.1
> Environment: Windows-7/64bit, Oracle/Sun JRE-1.6.x, JBoss-6.1.0 and standalone app (JSE)
> Reporter: Chris Wolf
> Priority: Minor
> Labels: OpenJPAConfiguration
>
> The documentation describes how to obtain a plain java.sql.Connection from the EntityManagerFactory, but it only works in a managed container environment (JEE). The page I'm referring to is here:
> http://openjpa.apache.org/builds/2.2.1/apache-openjpa/docs/manual.html#ref_guide_dbsetup_conn_from_factory_jpa
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira