jpa--数据源配置方法persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
    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">
    <persistence-unit name="TODS"  transaction-type="JTA">
        <provider>
            org.apache.openjpa.persistence.PersistenceProviderImpl
        </provider>
        <jta-data-source>jdbc/TODS</jta-data-source>
        <class>com.ibm.its.itmc.entity.Zone</class>
        <class>com.ibm.its.itmc.entity.Vms</class>
        <class>com.ibm.its.itmc.entity.AlertVms</class>
        <class>com.ibm.its.itmc.entity.AlertMessage</class>
        <class>com.ibm.its.itmc.entity.TrafficControl</class>
        <class>com.ibm.its.itmc.entity.Road</class>
        <class>com.ibm.its.itmc.entity.ResponsePlan</class>
        <class>com.ibm.its.itmc.entity.ResponseAction</class>
        <class>com.ibm.its.itmc.entity.RealtimeReportPK</class>
        <class>com.ibm.its.itmc.entity.RealtimeReport</class>
        <class>com.ibm.its.itmc.entity.Node</class>
        <class>com.ibm.its.itmc.entity.Message</class>
        <class>com.ibm.its.itmc.entity.Link</class>
        <class>com.ibm.its.itmc.entity.ForecastReportPK</class>
        <class>com.ibm.its.itmc.entity.ForecastReport</class>
        <class>com.ibm.its.itmc.entity.Event</class>
        <class>com.ibm.its.itmc.entity.Camera</class>
        <class>com.ibm.its.itmc.entity.LinkProfile</class>
        <class>com.ibm.its.itmc.entity.LinkProfilePK</class>

        <exclude-unlisted-classes>true</exclude-unlisted-classes>
       
        <properties>
          <property name="openjpa.jdbc.Schema" value="TODS" />      
          <property name="openjpa.jdbc.DBDictionary" value="db2" />      
          <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
          <property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO"/>
        </properties>
    </persistence-unit>
   
    <persistence-unit name="TADS" transaction-type="JTA">
        <provider>
            org.apache.openjpa.persistence.PersistenceProviderImpl
        </provider>
        <jta-data-source>jdbc/testVD</jta-data-source>
        <class>com.ibm.its.itmc.entity.TadsZone</class>
        <class>com.ibm.its.itmc.entity.TadsRoad</class>
        <class>com.ibm.its.itmc.entity.TadsLink</class>
        <class>com.ibm.its.itmc.entity.TadsNode</class>
        <class>com.ibm.its.itmc.entity.TadsDate</class>
        <class>com.ibm.its.itmc.entity.TadsLinkCatagory</class>
        <class>com.ibm.its.itmc.entity.TadsNodeCatagory</class>

        <exclude-unlisted-classes>true</exclude-unlisted-classes>
       
        <properties>
          <property name="openjpa.jdbc.Schema" value="TADS" />      
          <property name="openjpa.jdbc.DBDictionary" value="db2" />      
          <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
          <property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO"/>
        </properties>
    </persistence-unit>
</persistence>

方法二:数据源在工程内配置:
transaction-type="RESOURCE_LOCAL"和datasource的配置不同,

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
    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">
    <persistence-unit name="TODS" transaction-type="RESOURCE_LOCAL ">
        <provider>
            org.apache.openjpa.persistence.PersistenceProviderImpl
        </provider>
      
        <class>com.ibm.its.itmc.entity.Zone</class>
        <class>com.ibm.its.itmc.entity.Vms</class>
        <class>com.ibm.its.itmc.entity.TrafficControl</class>
        <class>com.ibm.its.itmc.entity.Road</class>
        <class>com.ibm.its.itmc.entity.ResponsePlan</class>
        <class>com.ibm.its.itmc.entity.ResponseAction</class>
        <class>com.ibm.its.itmc.entity.RealtimeReportPK</class>
        <class>com.ibm.its.itmc.entity.RealtimeReport</class>
        <class>com.ibm.its.itmc.entity.Node</class>
        <class>com.ibm.its.itmc.entity.Message</class>
        <class>com.ibm.its.itmc.entity.Link</class>
        <class>com.ibm.its.itmc.entity.ForecastReportPK</class>
        <class>com.ibm.its.itmc.entity.ForecastReport</class>
        <class>com.ibm.its.itmc.entity.Event</class>
        <class>com.ibm.its.itmc.entity.Camera</class>
        <class>com.ibm.its.itmc.entity.TmLinkProfile</class>
        <class>com.ibm.its.itmc.entity.TmLinkProfilePK</class>

       

        <exclude-unlisted-classes>true</exclude-unlisted-classes>
       
       
        <<properties>
            <property name="openjpa.ConnectionURL" value="jdbc:db2://9.123.109.152:50000/TODS" />
            <property name="openjpa.ConnectionDriverName" value="com.ibm.db2.jcc.DB2Driver" />
            <property name="openjpa.Log" value="none" />
            <property name="openjpa.ConnectionUserName" value="db2admin" />
            <property name="openjpa.ConnectionPassword" value="passw0rd" />
            <property name="openjpa.jdbc.TransactionIsolation" value="read-committed" />
            <property name="openjpa.jdbc.Schema" value="TODS" />
        </properties>
   
    </persistence-unit>
</persistence>

你可能感兴趣的:(properties,jdbc,db2,encoding)