<?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns:persistence="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 persistence_1_0.xsd "> <!-- Name屬性用於定義持久化單元的名字 (name必選,空值也合法); transaction-type 指定事務類型(可選) --> <persistence-unit name="unitName" transaction-type="JTA"> <!-- 描述信息.(可選) --> <description> </description> <!-- javax.persistence.PersistenceProvider接口的一個實現類(可選) --> <provider> </provider> <!-- Jta-data-source和 non-jta-data-source用於分別指定持久化提供商使用的JTA和/或non-JTA數據源的全局JNDI名稱(可選) --> <jta-data-source>java:/MySqlDS</jta-data-source> <non-jta-data-source> </non-jta-data-source> <!-- 聲明orm.xml所在位置.(可選) --> <mapping-file>product.xml</mapping-file> <!-- 以包含persistence.xml的jar文件爲基準的相對路徑,添加額外的jar文件.(可選) --> <jar-file>../lib/model.jar</jar-file> <!-- 顯式列出實體類,在Java SE 環境中應該顯式列出.(可選) --> <class>com.domain.User</class> <class>com.domain.Product</class> <!-- 聲明是否掃描jar文件中標註了@Enity類加入到上下文.若不掃描,則以下:(可選) --> <exclude-unlisted-classes/> <!-- 廠商專有屬性(可選) --> <properties> <!-- hibernate.hbm2ddl.auto= create-drop / create / update --> <property name="hibernate.hbm2ddl.auto" value="update" /> <property name="hibernate.show_sql" value="true" /> </properties> </persistence-unit> </persistence>