用xdoclet自动生成hibernate的映射文件,配置文件

http://sourceforge.net/

下载xdoclet-plugins-dist-1.0.4。

 

 

如果在eclipse下的话,不需要配置(如果没有ide需要安装好ant)

 

build.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<project name="oa" default="hibernatecfg" basedir=".">
	<property name="src.dir" value="${basedir}/src" />
	<property name="xdoclet.home" value="D:/soft/xdoclet" />

	<path id="xdoclet.classpath">
		<fileset dir="${xdoclet.home}/xdoclet-plugins-dist-1.0.4/lib">
			<include name="**/*.jar" />
		</fileset>
	</path>
	<taskdef name="xdoclet" classname="org.xdoclet.ant.XDocletTask"
		classpathref="xdoclet.classpath" />

	<target name="hibernatecfg">
		<xdoclet>
			<fileset dir="${src.dir}/com/lmning/model">
				<include name="**/*.java" />
			</fileset>
			<component
				classname="org.xdoclet.plugin.hibernate.HibernateConfigPlugin"
				destdir="${src.dir}" version="3.0" hbm2ddlauto="update"
				jdbcurl="jdbc:mysql://127.0.0.1/oa"
				jdbcdriver="com.mysql.jdbc.Driver" jdbcusername="root"
				jdbcpassword="1234" dialect="org.hibernate.dialect.MySQLDialect"
				showsql="true" />
		</xdoclet>
	</target>

	<target name="mapping">
		<xdoclet>
			<fileset dir="${src.dir}/com/lmning/model">
				<include name="**/*.java" />
			</fileset>
			<component
				classname="org.xdoclet.plugin.hibernate.HibernateMappingPlugin"
				version="3.0" destdir="${src.dir}" />
		</xdoclet>
	</target>
</project>

 

 model:

 

package com.lmning.model;

/**
 * 
 * @author Administrator
 * @hibernate.class table="User"
 */
public class User {
	
	/**
	 * @hibernate.id
	 * 		generator-class="native"
	 */
	private int id;
	
	/**
	 * @hibernate.property
	 */
	private String name;
	
	/**
	 * @hibernate.property
	 */
	private String sex;
			
	/**
	 * @hibernate.property
	 */
	private String phone;
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public Orgnization getOrg() {

}

 

 

运行ant,ok,User.hbm.xml和hibernate.cfg.xml就自动生成了。

 

你可能感兴趣的:(mysql,xml,Hibernate,ant,jdbc)