Hibernate Reverse Engineering没有生成正确的域代码STS

时间:2018-03-29 03:32:07

标签: java mysql spring hibernate reverse-engineering

我已经在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,并且所有变量都应包含正确的注释。但它在生成的代码中不存在。

3 个答案:

答案 0 :(得分:1)

在“导出程序”标签中,确保选中Generate EJB3 annotations

答案 1 :(得分:1)

除了Generate EJB3 annotations之外,请务必在休眠配置“主要”标签中选择Annotations (jdk 1.5+)

答案 2 :(得分:0)

您需要确保将Hibernate版本选择为5.2。

enter image description here