use hibernate-tools and ant create hbm files

本文阐述了如何使用ant生成Hibernate映射文件,可作为hibernatesynchronizer-3.1.9的替代方案。
JDK1.4.2_*
Ant 1.6+
Hibernate3
Hibernate-Tools

build.xml

 
<project name="build.xml" default="build">
<property name="lib.path" value="WebContent/WEB-INF/lib" />
<property name="out.path" value="JavaSource/ca/cbc/formhander" />
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpath="
${lib.path}/hibernate-tools.jar;
${lib.path}/slf4j-api-1.5.2.jar;
${lib.path}/slf4j-log4j12-1.5.2.jar;
${lib.path}/commons-collections-3.2.1.jar;
${lib.path}/dom4j-1.6.1.jar;
${lib.path}/freemarker.jar;
${lib.path}/jtidy-r8-20060801.jar;
${lib.path}/mysql-connector-java-5.1.6-bin.jar;
${lib.path}/log4j-1.2.15.jar;
${lib.path}/cglib-nodep-2.1_3.jar;
${lib.path}/commons-logging-1.1.1.jar;
${lib.path}/hibernate-3.3.1.ga.jar
" />
<target name="db2hbm">
<hibernatetool destdir="${out.path}">
<jdbcconfiguration configurationfile="hibernate.cfg.xml" packagename="ca.cbc.formhandler" revengfile="hibernate.reveng.xml" />
<hbm2hbmxml />
</hibernatetool>
</target>
<target name="build" />
</project>

hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="s">
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="hibernate.connection.username">root</property>
 
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
 
</session-factory>
</hibernate-configuration>

hibernate.reveng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
 
<hibernate-reverse-engineering>
<table-filter match-catalog="test" match-name="employee"/>
</hibernate-reverse-engineering>

参考资料

http://forums.hibernate.org/viewtopic.php?p=2286830&sid=5f7fff92d5bdc17e92ff86f8e44ce5ca

原创文章,转载请注明: 转载自海波无痕

本文链接地址: use hibernate-tools and ant create hbm files

文章的脚注信息由WordPress的wp-posturl插件自动生成

此条目发表在javaee分类目录,贴了, , , , 标签。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

评论链接可以 移除 nofollow.