Re: MyBatis generator with sqlite gives "did not resolve to any tables"

602 views
Skip to first unread message

Jeff Butler

unread,
Oct 19, 2012, 1:05:35 PM10/19/12
to mybati...@googlegroups.com
sqlite does not have catalogs - leave that off.

Only use the schema if you create tables like schema.table_name. Else
leave that off too.

You probably only need to specify the tableName.

Jeff Butler


On Fri, Oct 19, 2012 at 12:10 PM, cha <cha...@gmail.com> wrote:
> Hello, I am having a problem with MyBatis generator on sqlite.
> When I try to generate, I get
>
> "Generation Warnings Occured
> Table configuration with catalog main, schema sqlite_master, and table
> testTable did not resolve to any tables"
>
> The table config that I am using is
>
> <table catalog="main" schema="sqlite_master" tableName="testTable" >
> <property name="useActualColumnNames" value="true"/>
> </table>
>
> I have also tried variations like
>
> <table catalog="main" schema="sqlite" tableName="testTable" >
> <property name="useActualColumnNames" value="true"/>
> </table>
>
> <table schema="sqlite" tableName="testTable" >
> <property name="useActualColumnNames" value="true"/>
> </table>
>
> Has anyone used succesfully used MyBatis generator with sqlite and know the
> schema settings?

cha

unread,
Oct 19, 2012, 1:55:56 PM10/19/12
to mybati...@googlegroups.com
Thanks for the reply. Originally, I left catalog and schema off and got
 
"Generation Warnings Occured
  Table configuration with catalog null, schema null, and table testTable did not resolve to any tables"
 
Which made me think I needed schema/catalog settings. The entire generatorConfig.xml is
 
<?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="context">
    <jdbcConnection driverClass="org.sqlite.JDBC" connectionURL="jdbc:sqlite:testDB.sqlite" userId="" password="" ></jdbcConnection>
    <javaModelGenerator targetPackage="model" targetProject="test/src" ></javaModelGenerator>
    <sqlMapGenerator targetPackage="model" targetProject="test/src" ></sqlMapGenerator>
    <javaClientGenerator targetPackage="model" targetProject="test" type="XMLMAPPER" ></javaClientGenerator>
    <table tableName="afloatplantest" >

      <property name="useActualColumnNames" value="true"/>
    </table>
  </context>

Jeff Butler

unread,
Oct 19, 2012, 2:20:42 PM10/19/12
to mybati...@googlegroups.com
I'm not an SQLite user, so I don't know for sure. You might try
setting schema to "testDB.sqlite". You might also try setting catalog
to "testDB" and schema to "sqlite". It's really dependent on how they
implemented the JDBC driver.

Jeff Butler

cha

unread,
Oct 25, 2012, 3:44:27 PM10/25/12
to mybati...@googlegroups.com
Thanks, but I'm still having problems here. Do you know of anyone who has gotten this to work with sqlite?
 
What would help is more failure information.  Is there a way to get more about why the table isn't resolved from the generator? For example the same error is given if the database file testDB_DNE.sqlite doesn't exist as a table, schema, or catalog that doesn't exist.
 
Another way to fix this might be to just hand feed the tables' "create table ..." or something like that to the generator instead of having it instrospect. Is this possible?

Jeff Butler

unread,
Oct 25, 2012, 4:12:28 PM10/25/12
to mybati...@googlegroups.com
My best guess is that there is a problem with the SQLite JDBC driver -
either a bug or they have not implemented the
DatabaseMetaData.getColumns() method.

You can check it yourself with a small Java program. This is
virtually what the generator does:

Connection c = getConnection(); // you must write the getConnection method
DatabaseMetaData dbmd = c.getMetaData();
ResultSet rs = dbmd.getColumns(catalog, schema, table, null);

If the ResultSet comes back empty, then you'll see the message your
are seeing. The driver is not throwing an error, it's just returning
nothing. So there is no better error information to display.

You'll have to experiment with values for catalog, schema, and table
to see if you can get something to come back, You can set all four
parameters to null which should return information about every column
in the database (a long list). That would give you a clue as to what
needs to be entered.

Another issue could be case sensitivity. If SQLite is case sensitive
in the metadata then you will need to specify the proper case and set
the table configuration to use delimited parameters.

As for your other question about passing in a create table statement,
there is no support for that in the generator.

Jeff Butler

cha

unread,
Oct 25, 2012, 7:37:42 PM10/25/12
to mybati...@googlegroups.com
Hmmm, if it uses getMetaData it should be fine. The ResultSet comes back with the expected
 

null, null, tableName, col1Name, 12, TEXT, 2000000000 ...

for each column. Oddly enough it still gives the same answer if wrong catalog and schema is given like dbmd.getColumns(wrongCatalog, wrongSchema, tableName, null).

You mentioned that I try dbmd.getColumns(null, null, null, null) to get a list of all the columns in the database. Using four nulls this way returns an empty ResultSet. This might be the problem if the generator calls getColumns(null, null, null, null) at some point (say, to get a feel for the entire database).

Jeff Butler

unread,
Oct 25, 2012, 8:02:50 PM10/25/12
to mybati...@googlegroups.com
I looked at the source code for their driver. It ignores catalog and
schema - so it doesn't matter what you put there. It is also case
sensitive.

The generator never calls getColumns with 4 nulls - that's just a
debugging technique.

This is probably a case sensitivity problem. In your generator
config, specify this:

<table tableName="yourTableName" />

Specify the tableName in the same case you used in your test program.

Jeff Butler

cha

unread,
Oct 25, 2012, 8:12:56 PM10/25/12
to mybati...@googlegroups.com
I'm pretty sure it isn't case sensive, tableName, TABLENAME, and tablename all return the same metadata. Anyways, the case I am using is correct. Which driver says it uses case sensitivity? I'm using sqitejdbc.

<classPathEntry location="\mylocation\sqlitejdbc-v056.jar" />

Jeff Butler

unread,
Oct 25, 2012, 8:18:54 PM10/25/12
to mybati...@googlegroups.com
I looked at this one:

http://www.xerial.org/maven/repository/artifact/org/xerial/sqlite-jdbc/3.7.2/

The source for org.sqlite.MetaData reports that it is case sensitive
(storesMixedCaseIdentifiers() returns true).

I think you need to load up the generator in a debugger and step into
the driver to see what's happening. Set a breakpoint in
org.mybatis.generator.internal.db.DatabaseIntrospector.getColumns()
method.

Jeff Butler
Reply all
Reply to author
Forward
0 new messages