MyEclipse的版本是8.5,新建一个实体类,在实体类中需要使用annotation进行标注,代码如下:
package entity;
import java.io.Serializable;
/**
* @hibernate.mapping default-laze="false"
* @hibernate.class table="PERSON"
* @hibernate.comment 员工
*/
public class Person implements Serializable {
private static final long serialVersionUID = 2583508512288182544L;
private long id;
private String name;
private Integer age;
/**
* @hibernate.id generator-class="native"
* @hibernate.column name="ID" comment="标识"
*/
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
/**
* @hibernate.property type="string" length="50" not-null="true"
* @hibernate.column name="PNAME" comment="姓名"
*/
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
* @hibernate.property type="integer" not-null="true"
* @hibernate.column name="PAGE" comment="年龄"
*/
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
在这个项目上右键-->属性,在弹出的项目属性设置框中,选择“MyEclipse-->XDoclect”,在Configuration配置页中,点击“Add Standard”,添加“Standard Hibernate”项,确认。然后同样是在项目上右键-->MyEclipse-->Run XDoclect,然后就会生成Person.hbm.xml文件,默认的格式真是惨不忍睹,使用Ctrl+Shift+F格式化一下,最终内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="entity.Person" table="PERSON">
<id name="id" type="long">
<column name="ID" />
<generator class="increment">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Person.xml containing the additional
parameters and place it in your merge dir.
-->
</generator>
</id>
<property name="name" type="string">
<column name="PNAME" />
</property>
<property name="age" type="integer">
<column name="PAGE" />
</property>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Person.xml containing the additional properties
and place it in your merge dir.
-->
</class>
</hibernate-mapping>
好了,至此hbm文件生成成功。
package entity;
import java.io.Serializable;
/**
* @hibernate.mapping default-laze="false"
* @hibernate.class table="PERSON"
* @hibernate.comment 员工
*/
public class Person implements Serializable {
private static final long serialVersionUID = 2583508512288182544L;
private long id;
private String name;
private Integer age;
/**
* @hibernate.id generator-class="native"
* @hibernate.column name="ID" comment="标识"
*/
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
/**
* @hibernate.property type="string" length="50" not-null="true"
* @hibernate.column name="PNAME" comment="姓名"
*/
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
* @hibernate.property type="integer" not-null="true"
* @hibernate.column name="PAGE" comment="年龄"
*/
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
在这个项目上右键-->属性,在弹出的项目属性设置框中,选择“MyEclipse-->XDoclect”,在Configuration配置页中,点击“Add Standard”,添加“Standard Hibernate”项,确认。然后同样是在项目上右键-->MyEclipse-->Run XDoclect,然后就会生成Person.hbm.xml文件,默认的格式真是惨不忍睹,使用Ctrl+Shift+F格式化一下,最终内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="entity.Person" table="PERSON">
<id name="id" type="long">
<column name="ID" />
<generator class="increment">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Person.xml containing the additional
parameters and place it in your merge dir.
-->
</generator>
</id>
<property name="name" type="string">
<column name="PNAME" />
</property>
<property name="age" type="integer">
<column name="PAGE" />
</property>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Person.xml containing the additional properties
and place it in your merge dir.
-->
</class>
</hibernate-mapping>
好了,至此hbm文件生成成功。