首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

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

2012-11-08 
使用Hibernate_tool生成代码和映射文件 (原创)?下载地址:http://www.hibernate.org/255.html它支持Eclispe

使用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

?

?

热点排行