schemacrawler java.lang.NullPointerException: Catalog could not be retrieved

201 Views Asked by At

I try to use schemacrawler with hsqldb 2.51 and h2 2.x with the following code:

final LimitOptionsBuilder limit = LimitOptionsBuilder.builder()
    .includeSchemas(new IncludeAll())
    .includeTables(new IncludeAll());
final LoadOptionsBuilder load = LoadOptionsBuilder.builder()
    .withSchemaInfoLevel(SchemaInfoLevelBuilder.minimum());
final SchemaCrawlerOptions options = SchemaCrawlerOptionsBuilder.newSchemaCrawlerOptions()
    .withLimitOptions(limit.toOptions())
    .withLoadOptions(load.toOptions());
final Catalog catalog = SchemaCrawlerUtility.getCatalog(connection, options);
// throw NullPointerException
for (final schemacrawler.schema.Table t : catalog.getTables())
{
    //more code...
}

I can't get the catalog without an NullPointerException error. I have two archives in the classpath:

  • schemacrawler-16.16.11.jar
  • schemacrawler-hsqldb-16.16.11.jar

If someone has an idea...

1

There are 1 best solutions below

1
psilocybe On

After changing some code I managed to have something that works...

new LoggingConfig(Level.ALL);
final LimitOptionsBuilder limit = LimitOptionsBuilder.builder()
    .includeSchemas(new IncludeAll())
    .includeTables(new IncludeAll());
final LoadOptionsBuilder load = LoadOptionsBuilder.builder()
    .withSchemaInfoLevel(SchemaInfoLevelBuilder.minimum());
final SchemaCrawlerOptions options = SchemaCrawlerOptionsBuilder.newSchemaCrawlerOptions()
    .withLimitOptions(limit.toOptions())
    .withLoadOptions(load.toOptions()); 
final SchemaRetrievalOptions retrieval = SchemaCrawlerUtility.matchSchemaRetrievalOptions(connection);
schemacrawler.crawl.SchemaCrawler crawler = new schemacrawler.crawl.SchemaCrawler(connection, retrieval, options);
final Catalog catalog = crawler.crawl();
for (final schemacrawler.schema.Table t : catalog.getTables())
    {
        //more code...
    }

However, the first code always gives me the same error...