Legacy database to POJO 关键字: Hibernate Tools

1, Download and install Hibernate Tool plugin

2, Run Hibernate Code Generation Configuations
2.1, set up reveng.xml ( choose legacy tables )
2.2, choose exporters ( java and/or hbm files )

3, Run the configuraiton to generate codes or hbm files.

3.1 java file Product.java
package test;

// Generated Jul 21, 2010 2:25:51 PM by Hibernate Tools 3.2.2.GA

/**
* Product generated by hbm2java
*/
public class Product implements java.io.Serializable {

private Integer id;
private String no;
private String name;

public Product() {
}

public Product(String no) {
this.no = no;
}

public Product(String no, String name) {
this.no = no;
this.name = name;
}

public Integer getId() {
return this.id;
}

public void setId(Integer id) {
this.id = id;
}

public String getNo() {
return this.no;
}

public void setNo(String no) {
this.no = no;
}

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

}

3.2, mapping file Product.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jul 21, 2010 2:25:51 PM by Hibernate Tools 3.2.2.GA -->
<hibernate-mapping>
    <class name="test.Product" table="product" catalog="MySQL">
        <id name="id" type="java.lang.Integer">
            <column name="ID" />
            <generator class="identity" />
        </id>
        <property name="no" type="string">
            <column name="NO" length="100" not-null="true" unique="true" />
        </property>
        <property name="name" type="string">
            <column name="NAME" length="100" />
        </property>
    </class>
</hibernate-mapping>

你可能感兴趣的:(java,xml,Hibernate,.net,UP)