【发布时间】:2018-09-07 21:50:10
【问题描述】:
我在 Spring 中启动了一个项目,并成功地在 Spring 上运行了一个示例应用程序,与 MySQL 数据库中的一个表进行通信。
现在,出于学习目的,我在同一个数据库中创建了另外两个表,并希望通过 Hibernate Tools 的逆向工程生成域类。 我关注了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,并且所有变量都应该包含一个适当的注解。但生成的代码中没有。
【问题讨论】:
标签: java mysql spring hibernate reverse-engineering