如何使 ha-jdbc 数据源工作

发布于 2024-10-16 12:46:47 字数 3306 浏览 1 评论 0原文

我有一个 ha-jdbc xml,其中有以下配置:

<ha-jdbc>
    <sync id="diff" class="net.sf.hajdbc.sync.DifferentialSynchronizationStrategy">
      <property name="fetchSize">1000</property>
      <property name="maxBatchSize">100</property>
    </sync>
    <sync id="full" class="net.sf.hajdbc.sync.FullSynchronizationStrategy">
      <property name="fetchSize">1000</property>
      <property name="maxBatchSize">100</property>
    </sync>
  <cluster balancer="load" 
       dialect="net.sf.hajdbc.dialect.MySQLDialect" 
       default-sync="full" 
       transaction-mode="parallel" 
       auto-activate-schedule="0 * * ? * *" 
       failure-detect-schedule="0 * * ? * *"
       meta-data-cache="none">
         <database id="database1">
               <driver>****</driver>
               <url>****</url>
               <user>****</user>
               <password>****</password>
         </database>
         <database id="database2">
               <driver>****</driver>
               <url>****</url>
               <user>****</user>
               <password>****</password>
         </database>
    </cluster>
  </ha-jdbc>

我正在使用 jpa 配置访问 ha-jdbc:

<?xml version="1.0" encoding="UTF-8"?>
<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="app_data" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <property name="hibernate.connection.driver_class" value="net.sf.hajdbc.sql.Driver" />
        <!--property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/-->
        <property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
        <property name="hibernate.connection.url" value="jdbc:ha-jdbc:cluster1" />
        <property name="hibernate.connection.username" value="****" />
        <property name="hibernate.connection.password" value="****" />
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
        <!--property name="hibernate.hbm2ddl.auto" value="update" /-->

        <property name="hibernate.c3p0.min_size" value="5" />
        <property name="hibernate.c3p0.max_size" value="20" />
        <property name="hibernate.c3p0.timeout" value="1800" />
        <property name="hibernate.c3p0.max_statements" value="50" />
        <property name="hibernate.c3p0.idle_test_period" value="3000" />
    </properties>
</persistence-unit>

当我运行 Maven 时,出现以下错误:

org.jibx.runtime.JiBXException:预期“集群”结束标记,找到“数据源”开始标记(第 19 行,第 11 列)

任何人都可以解释解决方案吗?

i have a ha-jdbc xml where i have this configuration:

<ha-jdbc>
    <sync id="diff" class="net.sf.hajdbc.sync.DifferentialSynchronizationStrategy">
      <property name="fetchSize">1000</property>
      <property name="maxBatchSize">100</property>
    </sync>
    <sync id="full" class="net.sf.hajdbc.sync.FullSynchronizationStrategy">
      <property name="fetchSize">1000</property>
      <property name="maxBatchSize">100</property>
    </sync>
  <cluster balancer="load" 
       dialect="net.sf.hajdbc.dialect.MySQLDialect" 
       default-sync="full" 
       transaction-mode="parallel" 
       auto-activate-schedule="0 * * ? * *" 
       failure-detect-schedule="0 * * ? * *"
       meta-data-cache="none">
         <database id="database1">
               <driver>****</driver>
               <url>****</url>
               <user>****</user>
               <password>****</password>
         </database>
         <database id="database2">
               <driver>****</driver>
               <url>****</url>
               <user>****</user>
               <password>****</password>
         </database>
    </cluster>
  </ha-jdbc>

i am accessing ha-jdbc using jpa config:

<?xml version="1.0" encoding="UTF-8"?>
<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="app_data" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <property name="hibernate.connection.driver_class" value="net.sf.hajdbc.sql.Driver" />
        <!--property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/-->
        <property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
        <property name="hibernate.connection.url" value="jdbc:ha-jdbc:cluster1" />
        <property name="hibernate.connection.username" value="****" />
        <property name="hibernate.connection.password" value="****" />
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
        <!--property name="hibernate.hbm2ddl.auto" value="update" /-->

        <property name="hibernate.c3p0.min_size" value="5" />
        <property name="hibernate.c3p0.max_size" value="20" />
        <property name="hibernate.c3p0.timeout" value="1800" />
        <property name="hibernate.c3p0.max_statements" value="50" />
        <property name="hibernate.c3p0.idle_test_period" value="3000" />
    </properties>
</persistence-unit>

when i run maven i get the following error:

org.jibx.runtime.JiBXException: Expected "cluster" end tag, found "datasource" start tag (line 19, col 11)

could anyone explain what can be the solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文