embeddable类有构造函数吗?

时间:2015-07-18 16:49:54

标签: java hibernate jpa

我有可嵌入注释的类,当尝试将实例传递给实体时,我得到异常

  

org.hibernate.InstantiationException:没有默认构造函数   entity :: entity.D3

enum Figure {
    SQUARE, TRIANGLE
};

@Embeddable
public class D3 {
    float z;
    @Enumerated(EnumType.STRING)
    Figure figure;

    public D3(float z, Figure f) {
        this.z = z;
        this.figure = f;
    }
}

1 个答案:

答案 0 :(得分:0)

除了您定义的任何内容之外,它正在寻找默认构造函数(即无参数):

@Embeddable
public class D3 {
    float z;
    @Enumerated(EnumType.STRING)
    Figure figure;

    public D3() { //I've added this
    }

    public D3(float z, Figure f) {
        this.z = z;
        this.figure = f;
    }
}