我有我的MySQL DB架構創建,我使用休眠反向工程文件來創建帶註釋的域對象(.java)。雖然文件生成正確,但它在某種程度上缺少ID字段的「生成器」註釋。HibernateTools反向工程工具不添加生成器的註釋
下面是我的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-name="products" match-catalog="test"></table-filter>
<table catalog="test" name="products">
<primary-key>
<generator class="native"></generator>
<key-column name="product_id"property="product_id" />
</primary-key>
</table>
</hibernate-reverse-engineering>
和生成的類文件(Products.java):
// default package
// Generated Jan 21, 2011 8:27:16 PM by Hibernate Tools 3.3.0.GA
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* Products generated by hbm2java
*/
@Entity
@Table(name = "products", catalog = "test")
public class Products implements java.io.Serializable {
private String productId;
private String productName;
public Products() {
}
public Products(String productId) {
this.productId = productId;
}
public Products(String productId, String productName) {
this.productId = productId;
this.productName = productName;
}
@Id
@Column(name = "product_id", unique = true, nullable = false, length = 50)
public String getProductId() {
return this.productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
@Column(name = "product_name", length = 200)
public String getProductName() {
return this.productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
}
有東西在我的hibernate.reveng.xml中文件丟失或休眠不會生成「發電機」的註釋?
經過一番搜索,我跟着一些幫助和作出以下修正:1)更新的product_id DB列的數據類型爲INT 2)已分配AUTO_INCREMENT屬性。現在,該工具能夠爲域生成器(Products.java)中的「@GeneratedValue」生成Native Generator的註釋。我仍然需要檢查它是否僅適用於INT列或其他數據類型的列,以及如何使其適用於VARCHAR列。 – mayur 2011-01-21 19:27:56