基于Ant+Hibernate Tools 的实体层生成方案
生成方案以DB-->hbm.xml-->Pojo为例
ant的build文件
问题
1.org.hibernate.cfg.JDBCBinderException: Duplicate class name 'com.kurui.kums._entity.Countries' generated for 'org.hibernate.mapping.Table(SH.COUNTRIES)'. Same name where generated for 'org.hibernate.mapping.Table(SH.COUNTRIES)'
Oracle下见此问题,在hibernate.properties里加上hibernate.default_schema=username 即可
2.表较多的情况下,可否将生成的hbm.xml和Pojo指定到不同的目录下?
3.关于使用模版。
实际需求中往往还需要为PoJo生成的过程中定义一些规则(首字母、前缀等、自定义代码等),网上资料看都提到了使用模版,如下:
<!--运用模板生成自己想要的类-->
生成pojo类,其实hbm2java,hbm2dao都是hbmtemplate的一个简化版本,可以用宏理解
其中hbm2java等价于:但是此处的模板位置都是在heibernate-tool.jar中。如果需要自定义模板,则需要明确编写hbmtemplate。
或者是
<hibernatetool destdir="${build.dir}/generated">
<classpath/>
<configuration configurationfile="hibernate.cfg.xml"/>
<!-- 用户模板 -->
<hbmtemplate exporterfilepattern="."/>
</hibernatetool>
我的问题是,Pojo.ftl和exporterclass如何定义、如何引用,可有案例可供参阅?