具有多个数据库的MyBatis Generator

时间:2014-06-27 13:54:14

标签: java xml spring mybatis mybatis-generator

我正在尝试使用三个表中的“MyBatis Generator”映射器生成,前两个在一个数据库中(derby sample),最后一个在另一个数据库中(BIRT示例)。

我正在使用带有德比的RAD 8.5。

这是我的xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
  PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

<generatorConfiguration>

  <classPathEntry location="C:\Users\XXX\IBM\rationalsdp\workspace\Example\WebContent\WEB-INF\lib\derby.jar"/>

  <!--  Primo database -->
    <context id="DerbyTables" targetRuntime="MyBatis3">

        <jdbcConnection driverClass="org.apache.derby.jdbc.EmbeddedDriver"
            connectionURL="jdbc:derby:C:\Users\XXX\IBM\rationalsdp\workspace\.metadata\.plugins\com.ibm.datatools.db2.cloudscape.driver\SAMPLE;create=true"
            userId="admin" password="admin">
        </jdbcConnection>

        <javaTypeResolver >
          <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>

        <javaModelGenerator targetPackage="test.model" targetProject="Example\src">
          <property name="enableSubPackages" value="true" />
          <property name="trimStrings" value="true" />
        </javaModelGenerator>

        <sqlMapGenerator targetPackage="test.dao.samp"  targetProject="Example">
          <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>

        <javaClientGenerator type="XMLMAPPER" targetPackage="test.dao"  
                                targetProject="Example\src">
          <property name="enableSubPackages" value="true" />
        </javaClientGenerator>

        <table schema="SAMP" tableName="STAFF" domainObjectName="staff">
            <property name="useActualColumnNames" value="true" />
        </table>

        <table schema="SAMP" tableName="SALES" domainObjectName="sales">
            <property name="useActualColumnNames" value="true" />
        </table>    

  </context>

  <!-- Secondo database -->
  <context id="SecondTables" targetRuntime="MyBatis3">
        <jdbcConnection driverClass="org.apache.derby.jdbc.EmbeddedDriver"
            connectionURL="jdbc:derby:C:\Users\XXX\IBM\rationalsdp\workspace\.metadata\.plugins\org.eclipse.birt.report.data.oda.jdbc.dbprofile.sampledb/db/BirtSample;create=true"
            userId="admin" password="admin">
        </jdbcConnection>

        <javaTypeResolver >
          <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>

        <javaModelGenerator targetPackage="test.model" targetProject="Example\src">
          <property name="enableSubPackages" value="true" />
          <property name="trimStrings" value="true" />
        </javaModelGenerator>

        <sqlMapGenerator targetPackage="test.dao.samp"  targetProject="Example">
          <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>

        <javaClientGenerator type="XMLMAPPER" targetPackage="test.dao"  
                                targetProject="E\src">
          <property name="enableSubPackages" value="true" />
        </javaClientGenerator>

        <table schema="CLASSICMODELS" tableName="OFFICES" domainObjectName="offices">
            <property name="useActualColumnNames" value="true"/>
        </table>      
  </context>

</generatorConfiguration>

当我在生成器配置文件上单击时,我收到以下错误:

无法启动数据库

'C:\Users\XXX\IBM\rationalsdp\workspace\.metadata\.plugins\org.eclipse.birt.report.data.oda.jdbc.dbprofile.sampledb/db/BirtSample' with class loader java.net.URLClassLoader@5ffe2fe7, see the next exception for details.
Failed to start database 'C:\Users\XXX\IBM\rationalsdp\workspace\.metadata\.plugins\org.eclipse.birt.report.data.oda.jdbc.dbprofile.sampledb/db/BirtSample' with class loader java.net.URLClassLoader@5ffe2fe7, see the next exception for details.

我找不到任何有关此问题的指南。

有人知道我的错误在哪里或者知道有关多个dbs的mybatis生成器的指南吗?

1 个答案:

答案 0 :(得分:0)

看起来您正在尝试连接到BIRT示例数据库。你的Derby数据库可能已经启动了。您可以添加; shutdown = true并运行一次,然后取消create = true并重试您的生成。