Openjpa slice executeUpdate for createNativeQuery

时间:2014-12-03 13:31:59

标签: java openjpa slice

是否可以在openjpa切片上对createNativeQuery使用executeUpdate? 我们尝试过类似的东西,但不会更新任何记录。我们正在使用 MySQL数据库。日志显示更新将转到两个切片并立即回滚。没有切片,一切都很好。

String updateQueryString = "update address set name = ?1 ";
 Query query = JPA.em().createNativeQuery(updateQueryString)
.setHint("openjpa.hint.slice.Target", “One”)
                .setParameter(1, "adr1");
query.executeUpdate();

我们的persistence.xml文件:

<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_2_0.xsd"  version="2.0">

   <persistence-unit name="slice">
        <provider>
             org.apache.openjpa.persistence.PersistenceProviderImpl
        </provider>
        <class>controllers.Address</class>
        <class>controllers.User</class>
        <class>models.Account</class>
        <class>controllers.CostCenter</class>
        <properties>
          <property name="openjpa.BrokerFactory" value="slice"/>
          <property name="openjpa.slice.Names" value="One, Two"/>
           <property name="openjpa.slice.Master" value="One"/>
          <property name="openjpa.ConnectionUserName" value="*****"/>
          <property name="openjpa.ConnectionPassword" value="******"/>
          <property name="openjpa.ConnectionDriverName"      
value="org.apache.openjpa.slice.jdbc"/>
          <property name="openjpa.slice.DistributionPolicy" 
value="sharding.RublysDistributionPolicy"/>
          <property name="openjpa.slice.QueryTargetPolicy " 
value="sharding.RublysQueryTargetPolicy"/>
          <property name="openjpa.slice.FinderTargetPolicy" 
value="sharding.RublysTargetPolicy" />
          <property name="openjpa.slice.ReplicatedTypes"
value="models.Account,controllers.CostCenter"/>
          <property name="openjpa.slice.One.ConnectionURL" 
        value="jdbc:mysql://localhost:3306/slice1"/>
          <property name="openjpa.slice.One.ConnectionDriverName"
value="com.mysql.jdbc.Driver"/>
          <property name="openjpa.slice.Two.ConnectionURL" 
        value="jdbc:mysql://localhost:3306/asrtest2"/>
          <property name="openjpa.slice.Two.ConnectionDriverName" 
value="com.mysql.jdbc.Driver"/>
          <property name="openjpa.DynamicEnhancementAgent" 
value="false"/>
         <property name="openjpa.Log" 
value="SQL=TRACE, Runtime=TRACE, DefaultLevel=TRACE ,Tool=TRACE"/>
        <property name="openjpa.Multithreaded"   value="true"/>
       <property name="openjpa.jdbc.SynchronizeMappings" value="refresh"/>
      <property name="openjpa.jdbc.MappingDefaults" value="DefaultMissingInfo=true"/>
      <property name="openjpa.jdbc.DBDictionary" value="mysql"/>
      <property name="openjpa.QueryCache" value="false"/>
      <property name="openjpa.DataCache" value="false"/>
      <property name="openjpa.QueryCompilationCache" value="false"/>
      <property name="openjpa.jdbc.QuerySQLCache" value="false"/>
          <property name="openjpa.jdbc.FinderCache" value="false"/>
          <property name="openjpa.DetachState" value="loaded(DetachedStateField=false)"/>
          <property name="openjpa.slice.ThreadingPolicy"     value="fixed"/>
   </properties>
    </persistence-unit>
</persistence>

0 个答案:

没有答案