persistence配置

persistence.xml配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for dev profile -->
<persistence 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_1_0.xsd"
version
="1.0">
<persistence-unit name="test">
<jta-data-source>java:/TestMySqlDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
</persistence>

test-ds.xml配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE datasources
PUBLIC "-//JBoss//DTD JBOSS JCA Config 5.0//EN"
"http://www.jboss.org/j2ee/dtd/jboss-ds_5_0.dtd"
>
<datasources>
<local-tx-datasource>
<jndi-name>TestMySqlDS</jndi-name>
<use-java-context>false</use-java-context>
<connection-url>jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=utf8&amp;autoReconnectForPools=true&amp;failOverReadOnly=false</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<transaction-isolation>TRANSACTION_REPEATABLE_READ</transaction-isolation>
<user-name>appuser</user-name>
<password>appuser</password>
<exception-sorter-class-name>com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter</exception-sorter-class-name>
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>

说明:如果应用发布在JBOSS下数据源名称一定要以:java:/为前缀,数据源的大小写敏感,persistence.xml和test-ds.xml都是放置在META-INF目录下面,同时数据源配置文件一定要命名为:XXX-ds.xml(一般命名为:数据库名+-ds.xml)的形式,


你可能感兴趣的:(配置)