我已经在Spring中启动了一个项目,并成功地在Spring上运行了一个示例应用程序,与MySQL数据库中的一个表进行通信。
现在,出于学习目的,我在同一个数据库中创建了两个表,并希望通过Hibernate Tools的Reverse Engineering生成域类。 我按照https://www.mkyong.com/hibernate/how-to-generate-code-with-hibernate-tools/本教程进行了操作。我的类正在生成,但它不包含实体/域类应包含的任何注释或映射。以下是为参考而生成的代码:
// default package
// Generated Mar 29, 2018 8:18:21 AM by Hibernate Tools 5.2.8.Final
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
/**
* Product generated by hbm2java
*/
public class Product implements java.io.Serializable {
private Integer productId;
private String productName;
private String createdBy;
private Date createdDate;
private String modifiedBy;
private Date modifiedDate;
private Set measurmentCategories = new HashSet(0);
public Product() {
}
public Product(String productName) {
this.productName = productName;
}
public Product(String productName, String createdBy, Date createdDate, String modifiedBy, Date modifiedDate,
Set measurmentCategories) {
this.productName = productName;
this.createdBy = createdBy;
this.createdDate = createdDate;
this.modifiedBy = modifiedBy;
this.modifiedDate = modifiedDate;
this.measurmentCategories = measurmentCategories;
}
public Integer getProductId() {
return this.productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public String getProductName() {
return this.productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getCreatedBy() {
return this.createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public Date getCreatedDate() {
return this.createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
public String getModifiedBy() {
return this.modifiedBy;
}
public void setModifiedBy(String modifiedBy) {
this.modifiedBy = modifiedBy;
}
public Date getModifiedDate() {
return this.modifiedDate;
}
public void setModifiedDate(Date modifiedDate) {
this.modifiedDate = modifiedDate;
}
public Set getMeasurmentCategories() {
return this.measurmentCategories;
}
public void setMeasurmentCategories(Set measurmentCategories) {
this.measurmentCategories = measurmentCategories;
}
}
但是,该类应包含注释@Entity,并且所有变量都应包含正确的注释。但它在生成的代码中不存在。