appfuse3 maven ,hibernate ,由数据库表生成对应的代码;
1 代码生成的一些命令 :
mvn appfuse:gen-model 根据数据库中建立的表结构生成对应的pojo类;
If you have tables with foreign key ift's necessary to alter the template src/test/resources/appfuse/model/Ejb3PropertyGetAnnotation.ftl
<#lt/>${pojo.generateJoinColumnsAnnotation(property, cfg)} instead of
<#lt/>${pojo.generateJoinColumnsAnnotation(property)}
to generate @ManyToOne anotations
(It's necessary to do mvn appfuse:copy-templates first)
If you want to generate your code in a sub-package, specify a full package name
like -Dentity=com.myproject.subpackage.model.Name or -Dentity=~.subpackage.model.Name. The tilde is a shortcut for ${groupId}.
<amp.genericCore>false</amp.genericCore>
2 appfuse 的俩种架构情况;
先说下俩个情况,对于maven的架构不同,例如使用 在一起的,即是 web,core在一个工程中;
对于这种情况的在进行代码生成时可以直接在项目的根路径下进行执行就可以;
还有是并行model 的,这样我们的Eclipse是有三个工程的,看起来是一个主的项目,一个core ,一个web 的,但是在存储的磁盘上是在一块的;
这样在执行amp的命令时,需要在core和web下分别进行执行操作; 对于自定义的代码模板同样要执行俩次;
3 其他
以mvn appfuse:gen-model 为例子:
对于在一块的好弄,直接在项目的根目录中使用: mvn appfuse:gen-model OK执行成功;
对于不在一起的,在根下总是报错,找不到jdbc.properties的错误 , 拿到源码发现:
if (getComponentProperty("configurationfile") == null) {
// look for jdbc.properties and set "propertyfile" to its path
File jdbcProperties = new File("target/classes/jdbc.properties");
if (!jdbcProperties.exists()) {
jdbcProperties = new File("target/test-classes/jdbc.properties");
}
if (jdbcProperties.exists()) {
if (getComponentProperty("propertyfile") == null) {
getComponentProperties().put("propertyfile", jdbcProperties.getPath());
getLog().debug("Set propertyfile to '" + jdbcProperties.getPath() + "'");
}
} else {
throw new MojoFailureException("Failed to find jdbc.properties in classpath.");
}
}
就不能在该目录下了,需要移到web所在的目录下,target下面的配置文件全的哦, 运行 mvn appfuse:gen-model 可以的。
这样执行完毕后,在进行执行 mvn appfuse:gen 选择生成的pojo 就可以完成了web中的代码生成了;
同样到core下面就可以对 core的相关的代码进行生成;
同样进行执行下;
代码生成从oracle表生成代码 : 从oracle生成代码时会扫描所表,崩溃。。。。如下除了一些warn ,倒是没有所有的进行扫描
A : 在jdbc中要指定如下方法 :
hibernatetool.metadatadialect=org.hibernate.cfg.reveng.dialect.OracleMetaDataDialect
B: 代码生成时一般会生成 hibernate.reveng.xml
内容一般如下:
<hibernate-reverse-engineering>
<type-mapping>
<!-- jdbc-type is name fom java.sql.Types -->
<sql-type jdbc-type="VARCHAR" length='1' hibernate-type="yes_no"/>
<!-- length, scale and precision can be used to specify the mapping precisly -->
<sql-type jdbc-type="NUMERIC" precision='1' hibernate-type="boolean"/>
<!-- the type-mappings are ordered. This mapping will be consulted last,
thus overriden by the previous one if precision=1 for the column -->
<sql-type jdbc-type="BIGINT" hibernate-type="java.lang.Long"/>
<sql-type jdbc-type="INTEGER" hibernate-type="java.lang.Long"/>
<sql-type jdbc-type="NUMERIC" hibernate-type="java.lang.Long"/>
</type-mapping>
<!-- BIN$ is recycle bin tables in Oracle -->
<table-filter match-name="BIN$.*" exclude="true"/>
<!-- Exclude AppFuse tables from all catalogs/schemas -->
<table-filter match-name="app_user" exclude="true"/>
<table-filter match-name="role" exclude="true"/>
<table-filter match-name="user_role" exclude="true"/>
<!-- 对于oracle指定要生成表,其他数据库可以不进行指定; -->
<table-filter match-schema="APPFUSE" match-name="TABLE1" exclude="true"/>
<table-filter match-schema="APPFUSE" match-name="TABLE2" exclude="false"/>
</hibernate-reverse-engineering>
红色部分就是我们要指定本次生成代码的表, match-schema 大写 , match-name 表名 , exclude 本次是否排除不生成