hibernate-tools.jar 核心类
用 ANT 工具完成 hbm.xml 文件转化成 pojo 持久类的流程
在 build.xml 文件中加入
<path id="toolslib">
<path location="lib/hibernate-tools.jar" />
<path location="lib/hibernate3.jar" />
<path location="lib/freemarker.jar" />
<path location="${jdbc.driver.jar}" />
</path>
假定 上面用到的 jars 都已经被导入到 lib 文件夹下。
添加 ANT 中的任务
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib" />
在 ANT 任务中 ,你需要明确以下几点
<hibernatetool
destdir="defaultDestinationDirectory" (1)
templatepath="defaultTemplatePath" (2)
>
<classpath ...> (3)
<property name="propertyName" value="value"/> <propertyset ...> (4)
(<configuration ...>|<annotationconfiguration ...>|<ejb3configuration ...>|<jdbcconfiguration ...>) (5)
(<hbm2java>,<hbm2cfgxml>,<hbmtemplate>,...*) (6)
</hibernatetool>
在我的实际的项目中只需要明确如下就 OK 了
<hibernatetool destdir="${build.dir}/generated" >
<configuration configurationfile="hibernate.cfg.xml"/>
<hbm2java/>
</hibernatetool>
(1) destdir 代表你要产生的pojo 类文件放置的位置 destination dir
(2)查找用户编辑的路径(3) (4) 都是可选项目
(5)选择其中一种 配置 hibernate 源数据(META )的模式,其中每种 Configuration 都有说道,详细请见Guide
(6)明确一种或两种导出的种类 这里选择 hbm2java
下面我们重点看一下 POJO java code exporter (<hbm2java>)
hbm2java是一个代码产生器,它可以控制可选项,包括是否支持 JDK 5.0 和 annotations
<hbm2java jdk5="true|false" ejb3="true|false" >
先写到这里,没完呢