我想堅持到DB 2實體:映射Java泛型字符串值
屬性
@Entity public class Attribute<T> { @Id @GeneratedValue(strategy = AUTO) Long id; @ManyToOne @JoinColumn(name = "item_id") Item item; String name; T value; boolean isTemplate; // skip setter and getter }
項目
public class Item { @Id @GeneratedValue(strategy = AUTO) Long id; @OneToMany(cascade = ALL) @JoinColumn(name= "item_id") List<Attribute> attributes; private boolean isTemplate; // skip setter and getter } in short Item 1-->* Attribute
錯誤消息,我得到的,因爲Hibernate不能映射T值;
所致:org.springframework.beans.BeanInstantiationException:無法實例[org.hibernate.SessionFactory實例]:出廠方法 '的sessionFactory' 拋出異常;嵌套的異常是org.hibernate.AnnotationException:屬性domain.item.Attribute.value具有未綁定的類型和沒有明確的目標實體。解決這個一般使用問題,或者設定一個明確的目標屬性(如@OneToMany(目標=),或使用一個明確的@Type
我只需要這個簡單的表
- 項目
| ID: INT | isTemplate:布爾| - 屬性
| ID:INT |名稱:字符串|類型:字符串(例如:字符串,整數 - >基於價值型)|值:字符串| fk_item_id |
- 項目
在此先感謝您提供任何幫助或建議以解決此問題。