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