方法一:多数据源的data source配置:
主要通过<jta-data-source>标签来配置。
<?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>
3 from local resource get JPA datasource way:
<?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="EVEP" transaction-type="RESOURCE_LOCAL">
<provider>
org.apache.openjpa.persistence.PersistenceProviderImpl
</provider>
<class>com.ibm.eve.core.entity.BatteryProfile</class>
<class>com.ibm.eve.core.entity.ConsumerAcct</class>
<class>com.ibm.eve.core.entity.ConsumerAcctBal</class>
<class>com.ibm.eve.core.entity.ConsumerAcctProviderSvc</class>
<class>com.ibm.eve.core.entity.ConsumerAcctProviderSvcPref</class>
<class>com.ibm.eve.core.entity.ConsumerToken</class>
<class>com.ibm.eve.core.entity.ConInfo</class>
<class>com.ibm.eve.core.entity.EnergyRt</class>
<class>com.ibm.eve.core.entity.EntityTag</class>
<class>com.ibm.eve.core.entity.Evse</class>
<class>com.ibm.eve.core.entity.EvseConn</class>
<class>com.ibm.eve.core.entity.EvseFees</class>
<class>com.ibm.eve.core.entity.Firmware</class>
<class>com.ibm.eve.core.entity.ListGenLog</class>
<class>com.ibm.eve.core.entity.Mkt</class>
<class>com.ibm.eve.core.entity.ModelProfile</class>
<class>com.ibm.eve.core.entity.ModelProfileIntvl</class>
<class>com.ibm.eve.core.entity.PhysicalAdr</class>
<class>com.ibm.eve.core.entity.Provider</class>
<class>com.ibm.eve.core.entity.ProviderInterop</class>
<class>com.ibm.eve.core.entity.ProviderSvc</class>
<class>com.ibm.eve.core.entity.ProviderSvcConsumerAcct</class>
<class>com.ibm.eve.core.entity.RechgTxn</class>
<class>com.ibm.eve.core.entity.RechgTxnIntvl</class>
<class>com.ibm.eve.core.entity.Reservation</class>
<class>com.ibm.eve.core.entity.SettlementLog</class>
<class>com.ibm.eve.core.entity.Xfmr</class>
<class>com.ibm.eve.core.entity.XfmrLoadForecast</class>
<exclude-unlisted-classes/>
<properties>
<property name="openjpa.ConnectionURL" value="jdbc:db2://9.39.92.17:50000/EVE_CTPA:retrieveMessagesFromServerOnGetMessage=true;" />
<property name="openjpa.ConnectionDriverName" value="com.ibm.db2.jcc.DB2Driver" />
<property name="openjpa.Log" value="SQL=TRACE" />
<property name="openjpa.ConnectionUserName" value="db2inst1" />
<property name="openjpa.ConnectionPassword" value="db2inst1" />
<property name="openjpa.jdbc.TransactionIsolation" value="none" />
<property name="openjpa.jdbc.Schema" value="EVE_CTPA" />
<property name="openjpa.RuntimeUnenhancedClasses" value="supported"/>
<property name="openjpa.Compatibility" value="StrictIdentityValues=false"/>
<property name="openjpa.jdbc.SchemaFactory" value="native(ForeignKeys=true)"/>
<property name="openjpa.AutoDetach" value="close, commit, nontx-read"/>
<!--
<property name="openjpa.ConnectionDriverName" value="com.ibm.db2.jcc.com.ibm.db2.jcc.DB2ConnectionPoolDataSource"/>
<property name="openjpa.ConnectionURL" value="jdbc:db2://9.115.68.242:50001/EVE:driverType=4;retrieveMessagesFromServerOnGetMessage=true;fullyMaterializeLobData=true;fullyMaterializeInputStreams=true;progressiveStreaming=2;progresssiveLocators=2;"/>
<property name="openjpa.ConnectionURL" value="jdbc:db2://localhost:50000/EVE" />
<property name="openjpa.ConnectionDriverName" value="com.ibm.db2.jcc.DB2Driver" />
<property name="openjpa.Log" value="SQL=TRACE" />
<property name="openjpa.ConnectionUserName" value="admin" />
<property name="openjpa.ConnectionPassword" value="oneclick" />
<property name="openjpa.jdbc.TransactionIsolation" value="read-committed" />
<property name="openjpa.jdbc.Schema" value="EVE" />
<property name="openjpa.RuntimeUnenhancedClasses" value="supported"/>
<property name="openjpa.Compatibility" value="StrictIdentityValues=false"/>
-->
</properties>
</persistence-unit>
</persistence>