【发布时间】:2015-09-16 16:33:29
【问题描述】:
我正在尝试将关联一对多映射到与 @Inheritance(strategy=InheritanceType.JOINED) 映射的实体,但在我的应用程序加载时出现验证异常:
内部异常:异常 [EclipseLink-7250](Eclipse 持久性 服务 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException 异常
描述:[class model.item.weapon.WeaponStat] 使用非实体 [class item.weapon.Weapon] 作为关系中的目标实体 属性[野战武器]。
这里是基类:
@Entity
@Table(name = "ITEMS")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "SYSTYPE", discriminatorType = DiscriminatorType.INTEGER)
@DiscriminatorValue(value = "0")
public class Item implements Serializable {...
继承自Item的类Weapon:
@Entity
@Table(name = "WEAPONS")
@PrimaryKeyJoinColumn(name = "ITEM_ID")
@DiscriminatorValue(value = "3")
public class Weapon extends Item {...
Weapon 包含OneToMany 属性:
@OneToMany(mappedBy = "weapon")
private List<WeaponStat> stats;
还有WeaponStat:
@Entity
@Table(name = "WEAPON_STATS")
public class WeaponStat implements Serializable {...
[...code...]
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "WEAPON_ID")
private Weapon weapon;
[...code...]
有人有想法吗?
【问题讨论】:
-
Weapon 是否与persistence.xml 文件中的所有其他实体一起正确列出?是否使用正确的 javax.persistence.Entity 注释进行了注释?
-
我实际上在我的 persistence.xml 中使用了
<exclude-unlisted-classes>false</exclude-unlisted-classes>。如果我用<class>...</class>手动指定所有实体,问题是一样的。是的,进口是正确的。 -
你不能把它设为私人武器武器; => 私人物品武器;我知道这并不总是实用的,但武器上的成员与物品上的成员不同违反了 LSP en.wikipedia.org/wiki/Liskov_substitution_principle
-
谢谢,确实是这个问题!但是 :(
Exception Description: Missing class for indicator field value [3] of type [class java.lang.Integer]. Descriptor: RelationalDescriptor(model.item.Item --> [DatabaseTable(ITEMS)])当我尝试访问Weapon时。如果我访问一个简单的Item一切都很好...... -
为什么要结合继承类型JOINED和判别器?
标签: jpa inheritance eclipselink bidirectional