Ryan Atwood
Ryan Atwood

Reputation: 152

MyBatisGenerator.generate(null) does nothing with no errors

I have a mysql database on my local machine and am trying to use mybatis to generate POJO classes for the 24 tables on this new database. I am using the example on the MyBatis website: http://mybatis.github.io/generator/running/runningWithJava.html

    List<String> warnings = new ArrayList<String>();
    boolean overwrite = true;
    File configFile = new File("c:\\Users\\Ryan\\InfinityWorkspace\\Infinity\\src\\com\\ajtech\\infinity\\mybatis\\mybatisGenerator.xml");
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(configFile);
    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);

    myBatisGenerator.generate(null);

When I run this code, there are no exceptions that occur in the console, but nothing gets generated / produced by running this code.

I was able to verify that the config file is found on my PC and that it parses it correctly and that the jdbc connection inside of the mybatisGenerator.xml file I have successfully connects me to the mysql database using the username / password I provided.

Any ideas why it doesn't generate any XML / POJO classes for me?

My mybatisGenerator.xml file looks like this:

<?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>
    <context id="infinityDBTables">
      <jdbcConnection connectionURL="jdbc:mysql://localhost:3307/infinitydb" 
        driverClass="com.mysql.jdbc.Driver"
        userId="Ryan"
        password="infinity">
      </jdbcConnection>

      <javaModelGenerator targetPackage="com.ajtech.infinity.database.dao.model" targetProject="\Infinity\src">
             <property name="trimStrings" value="true" />
    </javaModelGenerator>

    <sqlMapGenerator targetPackage="com.ajtech.infinity.database.dao" targetProject="\Infinity\src"/>

    <javaClientGenerator targetPackage="com.ajtech.infinity.database.dao.client" targetProject="\Infinity\src" type="XMLMAPPER"/>

    <table tableName="AccessLevel" schema="infinitydb"/>
    <table tableName="Brand" schema="infinitydb"/>
  </context>
</generatorConfiguration>

Now, I confess, I did notice that no matter what table names or schema names I provide in the table tags it still does nothing and gives no errors....could there be errors with the table names behind the scenes?

Upvotes: 0

Views: 932

Answers (1)

Ryan Atwood
Ryan Atwood

Reputation: 152

I was able to get the "mybatis-generator-core-1.3.2-sources.jar". Then, after debugging into the mybatis generator code, I was able to see that the "targetProject" values of "\Infinity\src" were not being read despite the fact that this appears to be exactly how the example is shown on the mybatis page: http://mybatis.github.io/generator/configreference/xmlconfig.html

So, when I changed the targetProject values to be the full path on my C: drive, it worked:

targetProject="C:\Users\Ryan\InfinityWorkspace\Infinity\src\">

Upvotes: 1

Related Questions