![](/img/trans.png)
[英]JPA Embeddable can have ElementCollection<Embeddable> property
[英]Can embeddable class have constructors?
我有一個帶有可嵌入注釋的類,當我嘗試將實例傳遞給實體時,出現異常:
org.hibernate.InstantiationException:實體沒有默認構造函數::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;
}
}
除了您定義的任何構造函數之外,它還在尋找默認構造函數(即無參數):
@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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.