`

Hibernate3中的hbm2java和hbm2ddl的ant脚本实现

阅读更多


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


2.Hibernate-tools这个插件的用法,见官方网站的flash演示,使用非常方便。
Ant脚本已经跟2有很大差别了,这个我折腾了一天多,终于搞定了,贴出来大家看一下,更详细的信息可以看 http://www.hibernate.org/hib_docs/tools/ant/



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插件来完成

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics