title: How to adapt persistence.xml file to connect JPA to a JDBC/MySQL database in Java EE environment (Tomcat + JSF)
body: <p>I am developing a Dynamic web project (Java EE) using JSF, PrimeFaces, JPA, and running on Tomcat 7.
  The project development is based on <a href="http://www.simtay.com/simple-crud-web-application-with-jsf-2-1-primefaces-3-5-maven-and-jpa/" rel="nofollow">http://www.simtay.com/simple-crud-web-application-with-jsf-2-1-primefaces-3-5-maven-and-jpa/</a>
  <br>Now I am developing the JPA part of the software. In past, when I developed some little things (as exercises) in Java SE, I used to use the following database properties:</p>
  
  <pre><code>jdbc.drivers=com.mysql.jdbc.Driver
  jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&amp;amp;characterEncoding=utf8
  jdbc.username=root
  jdbc.password=password
  </code></pre>
  
  <p>But now I am learning JPA on Java EE.</p>
  
  <p>In the book "Pro JPA 2 Mastering the Java trade Persistance API", Chapter 3, paragraph "Packaging It Up" you can read:</p>
  
  <blockquote>
    <p>In the Java EE environment, many properties required in the
    persistence.xml file for Java SE can be omitted. In Listing 3-32, you
    see the persistence.xml file from Listing 2-11 converted for
    deployment as part of a Java EE application. Instead of JDBC
    properties for creating a connection, we now declare that the entity
    manager should use the data source name “jdbc/EmployeeDS”. If the data
    source was defined to be available in the application namespace
    instead of the local component naming context then we might instead
    use the data source name of “java:app/jdbc/EmployeeDS”. The
    transaction- type attribute has also been removed to allow the
    persistence unit to default to JTA. The application server will
    automatically find entity classes, so even the list of classes has
    been removed. This example represents the ideal minimum Java EE
    configuration. Because the business logic that uses this persistence
    unit is implemented in a stateless session bean, the persistence.xml
    file would typically be located in the META-INF directory of the
    corresponding EJB JAR.</p>
  </blockquote>
  
  <p><strong>Listing 3-32. Defining a Persistence Unit in Java EE</strong></p>
  
  <pre><code>&lt;persistence&gt;
      &lt;persistence-unit name="EmployeeService"&gt;
          &lt;jta-data-source&gt;jdbc/EmployeeDS&lt;/jta-data-source&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p><strong>Listing 2-11. Elements in the persistence.xml File</strong></p>
  
  <pre><code>&lt;persistence&gt;
      &lt;persistence-unit name="EmployeeService" transaction-type="RESOURCE_LOCAL"&gt;
          &lt;class&gt;examples.model.Employee&lt;/class&gt;
          &lt;properties&gt;
              &lt;property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/&gt;
              &lt;property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527 EmpServDB;create=true"/&gt;
              &lt;property name="javax.persistence.jdbc.user" value="APP"/&gt;
              &lt;property name="javax.persistence.jdbc.password" value="APP"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>My question is: how can I adapt a generic persistence.xml file in Java EE environment to connect to a MySQL/JDBC database using the properties I entered at the top of the post?</p>