【已解决】jfinal生成oracle时,生成model等顺利通过,但是生成字典文件时报错

版本:3.6

Connected to the target VM, address: '127.0.0.1:8725', transport: 'socket'

2019-03-15 10:55:58:471 INFO [com.alibaba.druid.pool.DruidDataSource] {dataSource-1} inited

2019-03-15 10:55:58:602 DEBUG [druid.sql.Statement] {conn-10001, stmt-20000} executed. select * from FNE_COLLEGES_BILL_INFO where rownum < 1

2019-03-15 10:55:58:614 DEBUG [druid.sql.Statement] {conn-10001, stmt-20001} executed. select * from FNE_COLLEGES_BUSDATA where rownum < 1

2019-03-15 10:55:58:618 DEBUG [druid.sql.Statement] {conn-10001, stmt-20002} executed. select * from FNE_COLLEGES_BUSDATA_ITEM where rownum < 1

Build TableMeta ...

Skip table :CWXX

Skip table :GXJX_ZYXXSJLB

Skip table :GXXS_XJJBSJZLB

Skip table :GXXS_XSJBSJZL

Skip table :GXXS_ZSZLB

Skip table :GXXX_BJSJLB

Skip table :GXXX_YXSDWJBSJZL

Skip table :QSXX

2019-03-15 10:55:59:017 DEBUG [druid.sql.Statement] {conn-10001, stmt-20003} executed. select * from FNE_COLLEGES_BILL_INFO where rownum < 1

2019-03-15 10:55:59:024 DEBUG [druid.sql.Statement] {conn-10001, stmt-20004} executed. select * from FNE_COLLEGES_BUSDATA where rownum < 1

2019-03-15 10:55:59:030 DEBUG [druid.sql.Statement] {conn-10001, stmt-20005} executed. select * from FNE_COLLEGES_BUSDATA_ITEM where rownum < 1

Generate base model ...

Base Model Output Dir: D:\workspace\axinfu\tyfp_bs/src/main/java/com/axinfu/tyfp_bs/model

Generate model ...

Model Output Dir: D:\workspace\axinfu\tyfp_bs/src/main/java/com/axinfu/tyfp_bs/dao

Generate MappingKit file ...

MappingKit Output Dir: D:\workspace\axinfu\tyfp_bs/src/main/java/com/axinfu/tyfp_bs

Generate DataDictionary file ...

Data Dictionary Output Dir: D:\workspace\axinfu\tyfp_bs/src/main/java/com/axinfu/tyfp_bs/dao

Exception in thread "main" java.lang.RuntimeException: java.sql.SQLException: 流已被关闭

at com.jfinal.plugin.activerecord.generator.DataDictionaryGenerator.rebuildColumnMetas(DataDictionaryGenerator.java:214)

at com.jfinal.plugin.activerecord.generator.DataDictionaryGenerator.generate(DataDictionaryGenerator.java:70)

at com.jfinal.plugin.activerecord.generator.Generator.generate(Generator.java:289)

at com.axinfu.tyfp_bs.gen.GenModel.main(GenModel.java:57)

Caused by: java.sql.SQLException: 流已被关闭

at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)

at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:263)

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:271)

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:445)

at oracle.jdbc.driver.LongAccessor.getBytesInternal(LongAccessor.java:154)

at oracle.jdbc.driver.LongAccessor.getBytes(LongAccessor.java:126)

at oracle.jdbc.driver.LongAccessor.getString(LongAccessor.java:193)

at oracle.jdbc.driver.T4CLongAccessor.getString(T4CLongAccessor.java:417)

at oracle.jdbc.driver.OracleResultSetImpl.getString(OracleResultSetImpl.java:971)

at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:494)

at com.jfinal.plugin.activerecord.generator.DataDictionaryGenerator.rebuildColumnMetas(DataDictionaryGenerator.java:188)

... 3 more

Disconnected from the target VM, address: '127.0.0.1:8725', transport: 'socket'


Process finished with exit code 1


评论区

jounzhang

2019-03-15 11:23

JfinalContext.init();

DataSource dataSource = DbKit.getConfig().getDataSource();

String basePath = System.getProperty("user.dir") + "/src/main/java/com/axinfu/tyfp_bs";
String basePkg = "com.axinfu.tyfp_bs";

String baseModelPackageName = basePkg + ".model";
String baseModelOutputDir = basePath + "/model";

String modelPackageName = basePkg + ".dao";
String modelOutputDir = basePath + "/dao";

String mappingPackageName = basePkg;
String mappingOutputDir = basePath;

BaseModelGenerator myBaseModelGenerator = new BaseModelGenerator(baseModelPackageName, baseModelOutputDir);
myBaseModelGenerator.setTemplate("gen/model.e");

ModelGenerator modelGenerator = new ModelGenerator(modelPackageName, baseModelPackageName, modelOutputDir);
modelGenerator.setTemplate("gen/dao.e");

MappingKitGenerator mappingKitGenerator = new MappingKitGenerator(mappingPackageName, mappingOutputDir);
mappingKitGenerator.setTemplate("gen/mapping_kit.e");
mappingKitGenerator.setMappingKitClassName("_MappingKit");

Generator gernerator = new Generator(dataSource, myBaseModelGenerator, modelGenerator);
gernerator.setMappingKitGenerator(mappingKitGenerator);

gernerator.setMetaBuilder(new MetaBuilder(dataSource) {
@Override
protected boolean isSkipTable(String tableName) {
return !tableName.startsWith("FNE_");
}
});

gernerator.setDialect(new OracleDialect());
gernerator.setGenerateDaoInModel(true);
gernerator.setGenerateDataDictionary(true);
//gernerator.setRemovedTableNamePrefixes("t_");

gernerator.generate();

jounzhang

2019-03-15 14:39

@jfinal
该问题已解决,最终问题为dbMeta.getColumns方法拿到的结果,在oracle下ResultSet读取时,若通过rs.getXXX("key")的方式取值,原则上需要跟返回结果的字段先后顺序一致,当field1在field2之前,而取值时已经读取了field2,再读取field1时,就会出错。但经测试,该原则并不稳定,部分字段的前后顺序不会引发问题,部分前后顺序会引发问题,具体场景还需进一步研究或查阅相关文档。以下为jdk8的顺序:
TABLE_CAT
TABLE_SCHEM
TABLE_NAME
1 COLUMN_NAME
DATA_TYPE
2 TYPE_NAME
3 COLUMN_SIZE
BUFFER_LENGTH
4 DECIMAL_DIGITS
7 REMARKS
6 COLUMN_DEF
SQL_DATA_TYPE
SQL_DATETIME_SUB
CHAR_OCTET_LENGTH
ORDINAL_POSITION
5 IS_NULLABLE
SCOPE_CATALOG
SCOPE_SCHEMA
SCOPE_TABLE
SOURCE_DATA_TYPE
IS_AUTOINCREMENT
IS_GENERATEDCOLUMN

标了数字的为jfinal在生成字典时的读取顺序,更改为正确的前后顺序后,未继续出现该问题。

JFinal

2019-03-16 15:06

@jounzhang 感谢你的研究,已将研究成功更新至 jfinal 3.7