用Generator自动创建base时,疑问.

   JFinal 3.0

  1. 用Generator自动创建base时, 好像没有把表的 [注释] 信息带过来????    //mysql 

  2. 用Generator自动创建base时, 如果没有主键好像会报错.

Build TableMeta ...
一月 20, 2017 4:28:37 下午 com.alibaba.druid.pool.DruidDataSource info
信息: {dataSource-1} inited
Exception in thread "main" java.lang.RuntimeException: primaryKey required by active record pattern
	at com.jfinal.plugin.activerecord.generator.MetaBuilder.buildPrimaryKey(MetaBuilder.java:199)
	at com.jfinal.plugin.activerecord.generator.MetaBuilder.build(MetaBuilder.java:96)
	at com.jfinal.plugin.activerecord.generator.Generator.generate(Generator.java:217)
	at app.model._JFinalDemoGenerator.main(_JFinalDemoGenerator.java:52)


评论区

絮随风

2017-02-02 23:45

同问

JFinal

2017-02-03 22:06

简单回复一下:
1:注释信息的生成,与 baseModel、Model 生成所使用的反射方式有所不同,为了在多数据库类型之下保障其可靠性,并没有在此时生成注释,而是将注释生成到了字典文件之中。这里也有性能方面的考虑

2:jfinal 的 model 使用的是 Active Record 模式,该模式的根基是一个 model 对象对应于一条数据表记录,对应的方式是采用主键。如果确实没有主键就不能使用 active record 模式,从而也就不需要生成 model,此时用一下 Db + Record 模式即可

jfinal club 项目中有不使用 Active Record 模式的部分表的使用示例,可以考虑加入个俱乐部,下载专享福利 http://jfinal.com/club

JFinal

2017-02-03 22:07

@絮随风 一起回复了

bogon

2017-02-19 17:02

用旧版本没有问题

bogon

2017-02-19 17:03

新版本就出现这个问题,我把旧版本的生成代码放到新版本里面是不行的,但是用旧版本的连接相同数据库是可以的

xiehao2016

2017-05-09 09:29

在生成以前,获取表名,把不需要的关系表过滤掉就行了

vae

2017-05-22 15:30

@JFinal Active Record 模式 在表格设置主键后还是会报上述的错误??

JFinal

2017-05-22 15:33

@vae 有主键就不会报这个错误,建议升级到 jfinal 3.1,生成器出错以后提示信息更加友好,容易排查问题

vae

2017-05-22 15:50

@JFinal 恩恩 是的 3q

flower929

2017-06-06 13:59

我数据表建立了主键,在自动生成model时报“primaryKey required by active record pattern”这个错误

pangg

2017-06-18 12:57

D:\java\jdk1.7.0_80\bin\java -Didea.launcher.port=7537 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.3.2\bin" -Dfile.encoding=UTF-8 -classpath "D:\projectJava\jfinal_demo\WebRoot\WEB-INF\classes;D:\java\jdk1.7.0_80\jre\lib\charsets.jar;D:\java\jdk1.7.0_80\jre\lib\deploy.jar;D:\java\jdk1.7.0_80\jre\lib\ext\access-bridge-64.jar;D:\java\jdk1.7.0_80\jre\lib\ext\dnsns.jar;D:\java\jdk1.7.0_80\jre\lib\ext\jaccess.jar;D:\java\jdk1.7.0_80\jre\lib\ext\localedata.jar;D:\java\jdk1.7.0_80\jre\lib\ext\sunec.jar;D:\java\jdk1.7.0_80\jre\lib\ext\sunjce_provider.jar;D:\java\jdk1.7.0_80\jre\lib\ext\sunmscapi.jar;D:\java\jdk1.7.0_80\jre\lib\ext\zipfs.jar;D:\java\jdk1.7.0_80\jre\lib\javaws.jar;D:\java\jdk1.7.0_80\jre\lib\jce.jar;D:\java\jdk1.7.0_80\jre\lib\jfr.jar;D:\java\jdk1.7.0_80\jre\lib\jfxrt.jar;D:\java\jdk1.7.0_80\jre\lib\jsse.jar;D:\java\jdk1.7.0_80\jre\lib\management-agent.jar;D:\java\jdk1.7.0_80\jre\lib\plugin.jar;D:\java\jdk1.7.0_80\jre\lib\resources.jar;D:\java\jdk1.7.0_80\jre\lib\rt.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\ojdbc6.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\fst-2.29.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\Lagrange.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\javabuilder.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\jedis-2.7.2.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\c3p0-0.9.5.1.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\cron4j-2.2.5.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\druid-1.0.29.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\log4j-1.2.16.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\velocity-1.7.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\cos-26Dec2008.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\objenesis-2.1.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\fastjson-1.2.6.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\jcommander-1.48.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\slf4j-api-1.6.1.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\javabase64-1.3.1.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\velocity-1.7-dep.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\commons-pool2-2.3.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\freemarker-2.3.20.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\slf4j-jdk14-1.6.1.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\sqlite-jdbc-3.7.2.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\jackson-core-2.5.3.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\ehcache-core-2.6.11.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\javassist-3.19.0-GA.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\jackson-databind-2.4.3.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\google-zxing-core-3.2.1.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\jfinal-3.1-bin-with-src.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\google-zxing-javase-3.2.1.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\jackson-annotations-2.4.0.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\mchange-commons-java-0.2.10.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\javax.servlet.jsp.jstl-1.2.0.v201105211821.jar;D:\projectJava\jfinal_demo\WebRoot\WEB-INF\lib\org.apache.taglibs.standard.glassfish-1.2.0.v201112081803.jar;D:\apache-tomcat-8.0.37\lib\el-api.jar;D:\apache-tomcat-8.0.37\lib\jasper.jar;D:\apache-tomcat-8.0.37\lib\ecj-4.5.jar;D:\apache-tomcat-8.0.37\lib\jsp-api.jar;D:\apache-tomcat-8.0.37\lib\catalina.jar;D:\apache-tomcat-8.0.37\lib\jasper-el.jar;D:\apache-tomcat-8.0.37\lib\tomcat-api.jar;D:\apache-tomcat-8.0.37\lib\tomcat-jni.jar;D:\apache-tomcat-8.0.37\lib\catalina-ha.jar;D:\apache-tomcat-8.0.37\lib\servlet-api.jar;D:\apache-tomcat-8.0.37\lib\tomcat-dbcp.jar;D:\apache-tomcat-8.0.37\lib\tomcat-jdbc.jar;D:\apache-tomcat-8.0.37\lib\tomcat-util.jar;D:\apache-tomcat-8.0.37\lib\catalina-ant.jar;D:\apache-tomcat-8.0.37\lib\tomcat-coyote.jar;D:\apache-tomcat-8.0.37\lib\websocket-api.jar;D:\apache-tomcat-8.0.37\lib\tomcat-i18n-es.jar;D:\apache-tomcat-8.0.37\lib\tomcat-i18n-fr.jar;D:\apache-tomcat-8.0.37\lib\tomcat-i18n-ja.jar;D:\apache-tomcat-8.0.37\lib\annotations-api.jar;D:\apache-tomcat-8.0.37\lib\catalina-tribes.jar;D:\apache-tomcat-8.0.37\lib\tomcat-util-scan.jar;D:\apache-tomcat-8.0.37\lib\tomcat-websocket.jar;D:\apache-tomcat-8.0.37\lib\catalina-storeconfig.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.3.2\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.cb.util._JFinalDemoGenerator
Build TableMeta ...
Skip table :WWV_FLOW_DUAL100
Skip table :WWV_FLOW_LOV_TEMP
Skip table :WWV_FLOW_TEMP_TABLE
Exception in thread "main" java.lang.RuntimeException: java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符

at com.jfinal.plugin.activerecord.generator.MetaBuilder.build(MetaBuilder.java:102)
at com.jfinal.plugin.activerecord.generator.Generator.generate(Generator.java:231)
at com.cb.util._JFinalDemoGenerator.main(_JFinalDemoGenerator.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:193)
at oracle.jdbc.driver.T4CStatement.executeForDescribe(T4CStatement.java:873)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1167)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1289)
at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:1491)
at oracle.jdbc.driver.OracleStatementWrapper.executeQuery(OracleStatementWrapper.java:406)
at com.alibaba.druid.pool.DruidPooledStatement.executeQuery(DruidPooledStatement.java:140)
at com.jfinal.plugin.activerecord.generator.MetaBuilder.buildColumnMetas(MetaBuilder.java:221)
at com.jfinal.plugin.activerecord.generator.MetaBuilder.build(MetaBuilder.java:97)
... 7 more

Process finished with exit code 1

alw

2018-04-06 16:14

@flower929 我的也是

cyf123

2018-04-25 11:38

@JFinal 我只更新一个表,这个表增加了两个字段,但是自动生成model的时候报错:primaryKey required by active record pattern 这个错误。怎么处理?

JFinal

2018-04-25 12:40

@cyf123 这个表需要指定主键,因为 active record 设计模式依赖主键的存在,否则 model.save() model.update() 等方法就不知道是对哪个记录进行操作了

如果确实不想增加主键,可以使用 Db + Record 模式来操作这张表,也很方便,通常一些关联表用 Db + Record

cyf123

2018-04-25 13:16

@JFinal 这个表在库里边有主键啊,为什么运行生成model还是会报错

JFinal

2018-04-25 13:43

@cyf123 单步调试找出原因,问题的本质了解清楚了, 还出这个问题显然是不能靠猜解决的

热门反馈

扫码入社