我想坚持到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 |
- 项目
在此先感谢您提供任何帮助或建议以解决此问题。