[英]How to save a class in a entity class?
在實體類中創建對象時遇到一些麻煩。 我得到以下異常:
java.lang.IllegalArgumentException:A:name.A不是受支持的屬性類型
這是一個小代碼示例:
這是我的實體B類:
@Entity
public class B {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key key;
private ArrayList<A> token = new ArrayList<A>();
public Profile() {
this.token.add(new Token(1));
this.token.add(new Token(2));
this.token.add(new Token(3));
this.token.add(new Token(4));
}
}
這是我的標准A類:
public class A {
private Integer id = new Integer(0);
public A(int id) {
this.id = id;
}
}
我將B類保存在數據存儲區中。 在以下幾點,我得到了例外:
profile = new Profile();
em.persist(profile);
em.close(); //Exception
如果我在類B中注釋令牌對象,則一切正常。 如何在B中使用A類?
我認為問題在於A類沒有被識別為要管理的實體。 您能否在A類頂部使用以下注釋並查看。
@Embeddable
public class A
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.