【发布时间】:2017-06-22 16:40:24
【问题描述】:
我想持久化到 DB 2 实体中:
-
属性
@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 -
由于休眠无法映射 T 值而收到的错误消息;
原因:org.springframework.beans.BeanInstantiationException:无法实例化[org.hibernate.SessionFactory]:工厂方法'sessionFactory'抛出异常;嵌套异常是 org.hibernate.AnnotationException:属性 domain.item.Attribute.value 具有未绑定类型且没有明确的目标实体。解决此通用使用问题或设置显式目标属性(例如 @OneToMany(target=) 或使用显式 @Type
-
我只需要这个简单的表格
- 物品
| id:int | isTemplate:boolean | - 属性
| id:int |名称:字符串 | type:String (i.e:String,Integer - > based value type) |值:字符串 | fk_item_id |
- 物品
提前感谢您提供解决此问题的任何帮助或建议。
【问题讨论】: