使用Hibernate_tool生成代码和映射文件 (原创)

 

下载地址:http://www.hibernate.org/255.html
它支持Eclispe插件方式和Ant方式。这里主要将采用Ant方式。这样可以脱离Eclipse :)

1 准备好Hiberbate.properteis. 主要是告诉工具取哪的数据库和表格

hibernate.dialect org.hibernate.dialect.MySQLDialect
#hibernate.dialect org.hibernate.dialect.MySQLInnoDBDialect
#hibernate.dialect org.hibernate.dialect.MySQLMyISAMDialect
hibernate.connection.driver_class com.mysql.jdbc.Driver
hibernate.connection.url jdbc:mysql://localhost/uniform_user
hibernate.connection.username sso
hibernate.connection.password sso


2 编写Ant脚本。这一步是要定义ant任务,以及生成POJO和HBM.XML配置文件

《?xml version="1.0"?》
《project name="UniformUser Hibernate" default="all" basedir="."》

   《property name="name" value="yidong"/》
   《property name="web.dir"  value="F:/winson/project/sso/develop/UniformUser"/》
   《property name="ant.lib.dir"  value="D:/apache-ant-1.7.0/lib"/》
   《property name="hibernatetools.lib.dir"  value="H:/Open Source/Hibernate/HibernateTools-3.2.0.beta9a/plugins/org.hibernate.eclipse_3.2.0.beta9a/lib/tools"/》
 
   《path id="lib.class.path"》
      《fileset dir="${web.dir}/WebRoot/WEB-INF/lib"》
           《include name="*.jar"/》
      《/fileset》
      《fileset dir="${ant.lib.dir}"》
           《include name="*.jar"/》
      《/fileset》
      《fileset dir="${hibernatetools.lib.dir}"》
           《include name="*.jar"/》
      《/fileset》
   《/path》
 
   《taskdef name="hibernatetool"
          classname="org.hibernate.tool.ant.HibernateToolTask"
          classpathref="lib.class.path" /》


 《target name="all"》
     《hibernatetool destdir="${web.dir}/src"》
      
       《jdbcconfiguration propertyfile="${basedir}/hibernate.properties" packagename="${name}.sso.entity" /》 
         《hbm2java jdk5="true" /》            
         《hbm2hbmxml /》
         《hbm2cfgxml /》
         《hbm2dao /》
     《/hibernatetool》
 《/target》 
《/project》

任务all 用于生成POJO和DAO和映射文件及hibernate.cfg.xml
其中lib.class.path必须包括ant的lib目录以及hibernate、hibernate-tools的lib目录。

参考资料:http://blog.sina.com.cn/u/492db961010009ji

 

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值