0

我一直在学习使用databene benerator(最新的0.8.1),但我在尝试填充H2数据库时遇到了问题(以前是1.3.170,现在是1.3.171)。首先,我得到了目录空异常,但是在进一步阅读 benerator 文档(0.7.6)时,我发现了这个

When importing database metadata, you might encounter exceptions when Benerator tries to get metadata of catalogs or schemas it has no access privileges to. Usually can fix this by choosing the right schema for your database, e.g. <database id="db" ... schema="PUBLIC" />

Table X not found in the expected catalog Y and schema Z This message tells you, that you database configuration is wrong. Check and fix the 'schema' and 'catalog' settings in your database configuration, e.g. <database … catalog="main" schema="Z" />

所以我在数据库标签中明确写了目录和模式名称

    <database id="db"
        url="jdbc:h2:tcp://localhost/D:/databases/databaseName"
        driver="org.h2.Driver"
        schema="PUBLIC"
        user="admin"
        catalog = "DATABASENAME"
        password="xxxxxx"
    />

但是当 benerator 刚刚开始填充第一个表时,我开始收到 Table null 异常,这是堆栈跟踪

D:\test3> benerator benerator.xml
Local classpath: .;D:\databene-benerator-0.8.1\bin;D:\databene-benerator-0.8.1\lib\*
12:06:58,495 INFO  (main) [CONFIG] Running file benerator.xml
12:06:58,511 INFO  (main) [CONFIG] Benerator 0.8.1 build 2335
12:06:58,511 INFO  (main) [CONFIG] Java version 1.7.0_17
12:06:58,511 INFO  (main) [CONFIG] JVM Java HotSpot(TM) Client VM 23.7-b01 (Oracle   
Corporation)
12:06:58,511 INFO  (main) [CONFIG] OS Windows 7 6.1 (x86)
12:06:58,511 INFO  (main) [CONFIG] Installed JSR 223 Script Engines:
12:06:58,526 INFO  (main) [CONFIG] - Mozilla Rhino[js, rhino, JavaScript, javascript, 
ECMAScript, ecmascript]
12:06:58,526 INFO  (main) [CONFIG] Max heap size: 247 MB
12:06:58,636 DEBUG (main) [CONFIG] Initializing Script mapping from file org/databene 
/script/script.properties
12:06:59,837 DEBUG (main) [COMMENT] Reproduces an existing database
12:06:59,837 DEBUG (main) [COMMENT] defining a database that will be referred by the  
id 'db' later
12:06:59,868 DEBUG (main) [COMMENT] Drop the current tables and sequences if they 
already exist
12:06:59,884 INFO  (main) [EvaluateStatement] Executing script drop_hotel_tables.sql
12:07:00,118 INFO  (main) [JDBC] Connected to H2 1.3.171 (2013-03-17)
12:07:00,118 INFO  (main) [JDBC] Using driver H2 JDBC Driver 1.3.171 (2013-03-17)
12:07:00,118 INFO  (main) [JDBC] JDBC version 4.0
12:07:00,180 DEBUG (main) [COMMENT] Create the tables and sequences
12:07:00,180 INFO  (main) [EvaluateStatement] Executing script create_tables_h2.sql
12:07:00,227 DEBUG (main) [COMMENT] Generating a single constant profile...
12:07:00,305 INFO  (main) [JDBCDBImporter] Importing tables from environment '___temp'
12:07:00,336 INFO  (main) [DefaultDBSystem] Fetching table details and ordering  
tables  by dependency

12:07:00,508 INFO  (main) [TaskExecutor] Running task  
StateTrackingTaskProxy[GenerateAndConsumeTask(PROFILE)]
12:07:00,508 ERROR (main) [DescriptorRunner] Error in Benerator execution
    org.databene.commons.ObjectNotFoundException: Table null
    at org.databene.platform.db.DBSystem.getTable(DBSystem.java:802)
    at org.databene.platform.db.DBSystem.getWriteColumnInfos(DBSystem.java:744)
    at org.databene.platform.db.DBSystem.persistOrUpdate(DBSystem.java:831)
    at org.databene.platform.db.DBSystem.store(DBSystem.java:360)
    at  

    org.databene.benerator.storage.StorageSystemInserter.startProductConsumption(
    StorageSystemInserter.java:53)
    at   
    org.databene.benerator.consumer.AbstractConsumer.startConsuming(AbstractConsumer.
    java:47)
    at   
    org.databene.benerator.consumer.ConsumerProxy.startConsuming(
    ConsumerProxy.java:62)
    at org.databene.benerator.engine.statement.ConsumptionStatement.execute(
    ConsumptionStatement.java:53)
    at org.databene.benerator.engine.statement.GenerateAndConsumeTask.execute(
    GenerateAndConsumeTask.java:159)
    at org.databene.task.TaskProxy.execute(TaskProxy.java:59)
    at org.databene.task.StateTrackingTaskProxy.execute(StateTrackingTaskProxy.java:52)
    at org.databene.task.TaskExecutor.runWithoutPage(TaskExecutor.java:136)
    at org.databene.task.TaskExecutor.runPage(TaskExecutor.java:126)
    at org.databene.task.TaskExecutor.run(TaskExecutor.java:101)
    at org.databene.task.TaskExecutor.run(TaskExecutor.java:77)
    at org.databene.task.TaskExecutor.execute(TaskExecutor.java:71)
    at org.databene.benerator.engine.statement.GenerateOrIterateStatement.executeTask(
    GenerateOrIterateStatement.java:156)
    at org.databene.benerator.engine.statement.GenerateOrIterateStatement.execute(
    GenerateOrIterateStatement.java:99)
    at   
    org.databene.benerator.engine.statement.LazyStatement.execute(LazyStatement.
    java:58)
    at  
    org.databene.benerator.engine.statement.StatementProxy.execute(
    StatementProxy.java:46)
    at org.databene.benerator.engine.statement.TimedGeneratorStatement.execute(
    TimedGeneratorStatement.java:70)
    at    
    org.databene.benerator.engine.statement.SequentialStatement.executeSubStatements(
    SequentialStatement.java:52)
    at org.databene.benerator.engine.statement.SequentialStatement.execute(
    SequentialStatement.java:47)
    at org.databene.benerator.engine.BeneratorRootStatement.execute(
    BeneratorRootStatement.java:63)
    at   
    org.databene.benerator.engine.DescriptorRunner.execute(DescriptorRunner.java:127)
    at org.databene.benerator.engine.DescriptorRunner.runWithoutShutdownHook(
    DescriptorRunner.java:109)
    at org.databene.benerator.engine.DescriptorRunner.run(DescriptorRunner.java:102)
    at org.databene.benerator.main.Benerator.runFile(Benerator.java:99)
    at org.databene.benerator.main.Benerator.runFromCommandLine(Benerator.java:82)
    at org.databene.benerator.main.Benerator.main(Benerator.java:75)
12:07:00,617 INFO  (main) [CachingDBImporter] Exporting Database meta data of ___temp 
to cache file
12:07:00,695 INFO  (main) [CONFIG] Max. committed heap size: 15 MB

可能是什么问题,或者我忘了做什么?因为当我使用“复制和扩展现有数据库”创建项目时,benerator 正确捕获了所有表,甚至是主键和外键以及唯一约束。帮助将不胜感激,因为我还没有找到任何其他足够灵活、开源、可扩展并支持 JDBC 和 java 数据库的数据生成器

4

1 回答 1

0

这就是我终于意识到databene benerator的原因。如果您使用 mysql 作为您选择的数据库,请始终让数据库定义中的schemacatalog属性与数据库名称相同。像这样

<database id="db"
    url="jdbc:mysql://localhost:3306/DatabaseName"
    driver="org.h2.Driver"
    schema="DatabaseName"
    catalog = "DatabaseName"
    user="admin"
    password="xxxxxx"
/>

它会给你一个像

[WARNING] Table 'TableName' not found in the expected catalog 'DatabaseName' and schema 'DatabaseName'. I have taken it from catalog 'DatabaseName' and schema 'null' instead. You better make sure this is right and fix the configuration

但它实际上是在做你想做的事。我没有尝试过其他数据库,但我希望它也适用于它们。

于 2014-10-27T18:48:58.010 回答