I am developing a dynamic web project (Java EE) using JSF, PrimeFaces, JPA and working on Tomcat 7. The project development is based on http://www.simtay.com/simple-crud-web-application-with-jsf-2 -1-primefaces-3-5-maven-and-jpa /
Now I am developing a JPA piece of software. In the past, when I developed some little things (like exercises) in Java SE, I used the following database properties:
jdbc.drivers=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8 jdbc.username=root jdbc.password=password
But now I am learning JPA in Java EE.
In Pro JPA 2, Mastering the Perspective API for Java Trading, chapter 3, paragraph βPackaging It Up,β you can read:
In Java EE, many of the properties required in the persistence.xml file for Java SE may be omitted. In Listing 3-32, see the persistence.xml file in Listing 2-11, which was converted for deployment as part of a Java EE application. Instead of the JDBC properties to create the connection, we now declare that the manager object should use the data source name "jdbc / EmployeeDS". If the data source was defined as accessible in the application namespace instead of the naming context of local components, then we could instead use the data source name "java: app / jdbc / EmployeeDS". The transaction type attribute has also been removed to default to JTA. The application server will automatically find entity classes, so even the list of classes has been deleted. This example is an ideal minimum Java EE configuration. Since business logic using this persistence block is implemented in a session without a bean state, the persistence.xml file is usually located in the META-INF directory corresponding to the EJB JAR.
Listing 3-32. Defining a Save Unit in Java EE
<persistence> <persistence-unit name="EmployeeService"> <jta-data-source>jdbc/EmployeeDS</jta-data-source> </persistence-unit> </persistence>
Listing 2-11. Elements in persistence.xml
<persistence> <persistence-unit name="EmployeeService" transaction-type="RESOURCE_LOCAL"> <class>examples.model.Employee</class> <properties> <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/> <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527 EmpServDB;create=true"/> <property name="javax.persistence.jdbc.user" value="APP"/> <property name="javax.persistence.jdbc.password" value="APP"/> </properties> </persistence-unit> </persistence>
My question is: how can I adapt the general persistence.xml file in the Java EE environment to connect to the MySQL / JDBC database using the properties entered at the beginning of the message?