java在emp页面重写url_java-ee – 如何调整persistence.xml文件以将Jav...

平元明
2023-12-01

我正在使用JSF,PrimeFaces,JPA开发动态Web项目(Java EE),并在Tomcat 7上运行.

项目开发基于http://www.simtay.com/simple-crud-web-application-with-jsf-2-1-primefaces-3-5-maven-and-jpa/

现在我正在开发软件的JPA部分.在过去,当我在Java SE中开发一些小东西(作为练习)时,我曾经使用以下数据库属性:

jdbc.drivers=com.mysql.jdbc.Driver

jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8

jdbc.username=root

jdbc.password=password

但现在我正在学习Java EE上的JPA.

在“Pro JPA 2掌握Java贸易持久性API”一书的第3章“打包它”中,您可以阅读:

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.

清单3-32在Java EE中定义持久性单元

jdbc/EmployeeDS

清单2-11. persistence.xml文件中的元素

examples.model.Employee

我的问题是:如何使用我在帖子顶部输入的属性来调整Java EE环境中的通用persistence.xml文件以连接到MySQL / JDBC数据库?

 类似资料: