title: Get JDBC connection from EntityManager
body: <p>I've a web application that uses EJB 3. Persistence is managed by container so the entity manager is injected.</p>
  
  <pre><code>@PersistenceContext(name="Ejbs", type=PersistenceContextType.TRANSACTION)
  private EntityManager em;
  </code></pre>
  
  <p>I need in one of my EJB methods to get the jdbc connection. I've read that it is possible with the next code:</p>
  
  <pre><code>java.sql.Connection conn = em.unwrap(java.sql.Connection.class);
  </code></pre>
  
  <p>But I'm always getting null.</p>
  
  <p>Why? How could I obtain the underlying connection?</p>
  
  <p>UPDATE:</p>
  
  <p>After changing the datasource definition it started to work. I remove a line of my datasource definition and it started to work. The line I've removed was</p>
  
  <pre><code>&lt;driver-class&gt;oracle.jdbc.OracleDriver&lt;/driver-class&gt;
  </code></pre>
  
  <p>My datasource definion is:</p>
  
  <pre><code>&lt;datasource jta="true" jndi-name="java:/jboss/datasources/Unificado" pool-name="Unificado" enabled="true" use-ccm="true"&gt;
        &lt;connection-url&gt;jdbc:oracle:thin:@10.12.54.186:1522:prd&lt;/connection-url&gt;                    
        &lt;driver&gt;ojdbc6&lt;/driver&gt;
        &lt;security&gt;
           &lt;user-name&gt;unificado&lt;/user-name&gt;
           &lt;password&gt;*******&lt;/password&gt;
        &lt;/security&gt;
        &lt;validation&gt;                        
           &lt;validate-on-match&gt;false&lt;/validate-on-match&gt;
           &lt;background-validation&gt;false&lt;/background-validation&gt;
        &lt;/validation&gt;
        &lt;statement&gt;
           &lt;share-prepared-statements&gt;false&lt;/share-prepared-statements&gt;
        &lt;/statement&gt;
  &lt;/datasource&gt;
  </code></pre>