(转)Hibernate3中的hbm2java和hbm2ddl的ant脚本实现

本文介绍Hibernate Tools插件的安装与使用方法,包括如何通过Eclipse插件查找Hibernate-tools.jar,以及如何利用Ant脚本进行数据库模式生成(hbm2ddl)与Java代码生成(hbm2java)。还提供了一个同时完成数据库模式生成和Java代码生成的任务示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.Hibernate-tools.jar这个包已经不像以前那么好找了,现在是放在hibernate-tools这个eclipse插件里面,用的时候要从里面搜索一下才能找到。


2.Hibernate-tools这个插件的用法,见官方网站的flash演示,使用非常方便。
Ant脚本已经跟2有很大差别了,



Hbm2ddl:

代码
<target name="hbm2ddl">
<taskdef name="hbm2ddl"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="project.class.path"/>
<hbm2ddl destdir="${ schema.dir }">
<configuration configurationfile="${ source.root }/hibernate.cfg.xml" />
<hbm2ddl export="true" console="false" create="true" update="false" drop="false" outputfilename="bestunix.sql"/>
</hbm2ddl>
</target>



Hbm2java :

代码
<target name="hbm2java">
<taskdef name="hbm2java"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="project.class.path"/>
<hbm2java destdir="${ source.root }">
<configuration configurationfile="${ source.root }/hibernate.cfg.xml" />
<hbm2java generics="true" ejb3="false"/>
<cfg2hbm/>
</hbm2java>

</target>



同时完成两个任务:

代码
<target name="schemaexport">
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="project.class.path"/>
<hibernatetool destdir="${ source.root }">
<configuration configurationfile="${ source.root }/hibernate.cfg.xml" />
<hbm2ddl export="true" console="false" create="true" update="false" drop="false" outputfilename="bestunix.sql"/>
<hbm2java generics="true" ejb3="false"/>
<cfg2hbm/>
</hibernatetool>
</target>



3. 用来生成html格式的数据库文档<hbm2doc>在ant脚本中好像暂时不行,还是要借助Hibernate-tool这个Eclipse插件来完成

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值