title: Why do we have to give database credentials in persistence.xml
body: <p>We are using <code>JPA 2.0</code> and we created the datasource in websphere and tried to access the database through the J2SE application. We are getting Invalid Username and password error. If we give the user name and password in <code>persistence.xml</code> it works fine.</p>
  
  <p>Please anybody explain me why do we have to give the DB credentials in persistence.xml since we have the data source.</p>
  
  <p>Note: Data Source was created successfully and the test was success. </p>
  
  <p><strong>persistence.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.0"
        xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
  
        &lt;persistence-unit name="Printer"&gt;
  
              &lt;jta-data-source&gt;jdbc/TestDataSource&lt;/jta-data-source&gt;
  
              &lt;properties&gt;
                    &lt;property name="openjpa.Optimistic" value="false" /&gt;
                    &lt;property name="openjpa.LockManager" value="pessimistic" /&gt;
                    &lt;property name="javax.persistence.jdbc.user" value="admin" /&gt;
                    &lt;property name="javax.persistence.jdbc.password" value="admin#2" /&gt;
                  &lt;/properties&gt;
  
        &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>