JPA HIbernate在生成的类中缺少列

时间:2018-09-11 15:10:48

标签: java hibernate jpa

我有一个带有2个外键的实体。 此类已生成

@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(DcDataDomaninDs.class)
public abstract class DcDataDomaninDs_ {
    public static volatile SingularAttribute<DcDataDomaninDs, Integer> id;
    public static volatile SingularAttribute<DcDataDomaninDs, DatasetType> datasetType;

}

从下面生成的实体类。我看不到我在数据集类型和数据域之间所做的不同。我忽略了其他简单的列,因为它们工作正常。

@Entity
@Table(name = "DC_DATA_DMN_DS")
public class DcDataDomaninDs implements Serializable {

    private static final long serialVersionUID = 1L;

    public DcDataDomaninDs() {
    }

    @Id
    @Column(name="DMN_DS_ID")
    private int id;


    private DataDomain dataDomain;


    private DatasetType datasetType;

    public int getId() {
        return id;
    }

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

    @ManyToOne
    @JoinColumn(name="DATA_DMN_CD")
    public DataDomain getDataDomain() {
        return dataDomain;
    }

    public void setDataDomain(DataDomain dataDomain) {
        this.dataDomain = dataDomain;
    }

    @ManyToOne
    @JoinColumn(name="DS_TYP_CD")
    public DatasetType getDatasetType() {
        return datasetType;
    }

    public void setDatasetType(DatasetType datasetType) {
        this.datasetType = datasetType;
    }

}

生成的类DataDomain_和DatasetType_都在其中包含此连接类的集合

public static volatile SetAttribute<DataDomain, DcDataDomaninDs> dataDomainDs;
public static volatile SetAttribute<DatasetType, DcDataDomaninDs> dataDomainDs;

此处要求的是缺失实体的映射

@Entity
@Table(name = "DC_DATA_DMN")
public class DataDomain {

    @Id
    @Column(name = "DATA_DMN_CD",updatable = false,insertable = false, nullable = false, length = 30)
    private String code;

    @Column(name = "DATA_DMN_NM", nullable = false, length = 100)
    private String name;

    private Set<DcDataDomaninDs> dataDomainDs;

    @OneToMany( mappedBy = "dataDomain")
    public Set<DcDataDomaninDs> getDataDomainDs() {
        return dataDomainDs;
    }

我尝试运行不需要缺失值的测试并得到了响应

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 12.979 sec <<< FAILURE! - in .dao.DataDomainDsIT
testListAll(.dao.DataDomainDsIT)  Time elapsed: 8.404 sec  <<< ERROR!

org.unitils.core.UnitilsException: Method DataDomainDsIT.public org.springframework.context.ConfigurableApplicationContext .dao.DataDomainDsIT.createApplicationContext() (annotated with SpringApplicationContext) has thrown an exception
    at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:336)

1 个答案:

答案 0 :(得分:0)

DataDomain类不是可序列化的,就是这样。