2

从 Benerator (0.7.7) 开始,我在尝试为 Mysql 5.5 的测试表生成数据时遇到了一些问题。数据库。

benerator 脚本是: benerator_2.xml

<?xml version="1.0" encoding="UTF-8"?>
<setup xmlns="http://databene.org/benerator/0.7.7"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://databene.org/benerator/0.7.7 benerator-0.7.7.xsd"
        defaultEncoding="Cp1252"
        defaultDataset="DE"
        defaultLocale="de_DE"
        defaultLineSeparator="\r\n">


<import defaults="true"/>
<import domains="person"/>
<import domains="address"/>
 <import platforms="db" />

    <comment>
         Populates a database
    </comment>

    <comment>defining a database that will be referred by the id 'db' later</comment>
    <database id="db"
        url="jdbc:mysql://localhost:3306/benerator"
        driver="com.mysql.jdbc.Driver"
        catalog="benerator"
        user="root"
        password="Arthur"/>


    <execute target="db">
        drop table if exists customer;
    </execute>

    <bean id="sg" class="SequenceTableGenerator">
    <property name="database" ref="db"/>
    <property name="table" value="MY_TABLE"/>
    <property name="column" value="SEQ_VALUE"/>
    </bean> 
    <execute target="db">
        create table customer (
            id bigint  null auto_increment,
            name varchar(255),
            pword varchar(20),
            address varchar(100),
            phone varchar(20),
            primary key (id)
        );
    </execute>

<generate type="testtable" consumer="db,ConsoleExporter" count="1000">
        <id name="id" mode="ignored" />

        <variable name="person" generator="PersonGenerator"  locale="${locale}"/>
        <variable name="address" generator="AddressGenerator" />    
        <attribute name="n" min="1" max="42" distribution="cumulated"/>
    <attribute name="name" script="{ftl:${person.givenName} ${person.familyName}}" />
    <attribute name="pword" pattern="[A-Za-z0-9]{8,12}" />
    <attribute name="address" script="{ftl:${address.street} ${address.houseNumber} ${address.city} ${address.country} ${address.postalCode} }" />
    <attribute name="phone" script="{ftl:${address.mobilePhone}}" />
</generate>

</setup>

如图所示,表的主键,id 被声明为自动生成:

    id bigint  null auto_increment,
    ....
   primary key (id)

为了告诉 Benerator 让忽略字段“id”,我设置

<id name="id" mode="ignored" />

生成的命令行是:

benerator benerator_2.xml

这是输出:

17:47:02,823 INFO  (main) [CONFIG] Running file benerator_2.xml
17:47:02,825 INFO  (main) [CONFIG] Benerator 0.7.7 build 2164
17:47:02,827 INFO  (main) [CONFIG] Java version 1.6.0_23
17:47:02,827 INFO  (main) [CONFIG] JVM Java HotSpot(TM) 64-Bit Server VM 19.0-b0
9 (Sun Microsystems Inc.)
17:47:02,828 INFO  (main) [CONFIG] OS Windows 7 6.1 (amd64)
17:47:02,828 INFO  (main) [CONFIG] Installed JSR 223 Script Engines:
17:47:02,906 INFO  (main) [CONFIG] - Mozilla Rhino[js, rhino, JavaScript, javasc
ript, ECMAScript, ecmascript]
17:47:02,906 INFO  (main) [CONFIG] Max heap size: 853 MB
17:47:02,959 DEBUG (main) [CONFIG] Initializing Script mapping from file org/dat
abene/script/script.properties
17:47:04,012 DEBUG (main) [COMMENT] Populates a database
17:47:04,019 DEBUG (main) [COMMENT] defining a database that will be referred by
 the id 'db' later
17:47:04,059 INFO  (main) [EvaluateStatement] Executing inline script
17:47:06,622 INFO  (main) [JDBC] Connected to MySQL 5.5.16
17:47:06,622 INFO  (main) [JDBC] Using driver MySQL-AB JDBC Driver mysql-connect
or-java-5.1.12 ( Revision: ${bzr.revision-id} )
17:47:06,624 INFO  (main) [JDBC] JDBC version 3.0
17:47:07,530 INFO  (main) [EvaluateStatement] Executing inline script
17:47:08,492 INFO  (main) [JDBCDBImporter] Importing tables from ___temp
17:47:08,578 INFO  (main) [DBSystem] Fetching table details and ordering tables
by dependency
Exception in thread "main" java.lang.NullPointerException
        at org.databene.benerator.composite.AbstractGeneratorComponent.init(Abst
ractGeneratorComponent.java:65)
        at org.databene.benerator.engine.statement.GenerateAndConsumeTask.initSt
atements(GenerateAndConsumeTask.java:269)
        at org.databene.benerator.engine.statement.GenerateAndConsumeTask.init(G
enerateAndConsumeTask.java:119)
        at org.databene.benerator.engine.statement.GenerateOrIterateStatement.be
Initialized(GenerateOrIterateStatement.java:165)
        at org.databene.benerator.engine.statement.GenerateOrIterateStatement.ex
ecute(GenerateOrIterateStatement.java:106)
        at org.databene.benerator.engine.statement.LazyStatement.execute(LazySta
tement.java:58)
        at org.databene.benerator.engine.statement.StatementProxy.execute(Statem
entProxy.java:45)
        at org.databene.benerator.engine.statement.TimedGeneratorStatement.execu
te(TimedGeneratorStatement.java:66)
        at org.databene.benerator.engine.statement.SequentialStatement.executeSu
bStatements(SequentialStatement.java:51)
        at org.databene.benerator.engine.statement.SequentialStatement.execute(S
equentialStatement.java:46)
        at org.databene.benerator.engine.BeneratorRootStatement.execute(Benerato
rRootStatement.java:63)
        at org.databene.benerator.engine.DescriptorRunner.execute(DescriptorRunn
er.java:135)
        at org.databene.benerator.engine.DescriptorRunner.runWithoutShutdownHook
(DescriptorRunner.java:116)
        at org.databene.benerator.engine.DescriptorRunner.run(DescriptorRunner.j
ava:109)
        at org.databene.benerator.main.Benerator.runFile(Benerator.java:88)
        at org.databene.benerator.main.Benerator.runFromCommandLine(Benerator.ja
va:76)
        at org.databene.benerator.main.Benerator.main(Benerator.java:69)

所以我主要得到

Exception in thread "main" java.lang.NullPointerException

那么问题出在哪里?提前致谢

4

0 回答 0