Hi everybody
I was wondering if it's possible to get database connection properties through entity manager.
My persistence.xml looks like this
<persistence ...>
<persistence-unit name="default" transaction-type="JTA">
<jta-data-source>DatasourceForTestSystem</jta-data-source>
<class> some.package.and.some.Class </class>
...
</persistence-unit>
</persistence>
I want something like
String host = em.getSomeFunction().getProperties().get("server");
String database = em.getSomeFunction().getProperties().get("database");
or
String url = em.getSomeFunction().getConnectionPool().getURL();
where url is something like jdbc:oracle:thin:@1.2.3.4:5678:database
.
I'm using JDeveloper 12c with EclipseLink, an Oracle database and NO Hibernate.
Does somebody know how to get information about the connection properties?
Kind regards,
Stefi
-- UPDATE --
@Kostja: thx again for your help but as I mentioned in my post I do not use Hibernate at all.
I already tried to use the Connection.class like this
java.sql.Connection conn = em.unwrap(java.sql.Connection.class);
from here. I always got a NPE for the Connection as well as for getSession() in this statement
((JNDIConnector)em.unwrap(JpaEntityManager.class)
.getSession().getLogin().getConnector()).getName();
from here.
I'm quiet confused why any of these solutions work for me. Maybe I'm missing something :-(