我创建了一个抽象实体类,它定义了两个具体的子类:
@Entity(name="Zone")
@DiscriminatorColumn(name="type",
discriminatorType=DiscriminatorType.STRING,
length=10)
@Table(name="grZones")
public abstract class ZoneEntity extends AbstractEntity {
@Id
public String getIdent() ...
@Entity(name="RootZone")
@DiscriminatorValue(value="root")
public static class RootZone extends ZoneEntity { ... }
@Entity(name="Subzone")
@DiscriminatorValue(value="subzone")
public static class Subzone extends ZoneEntity { ... }
}
另一个引用抽象区域类的类:
@Entity(name="Device")
@Table(name="grDevices")
public class DeviceEntity {
public DeviceEntity() { }
@Id
@XmlTransient
public Long getID() { ... }
@JoinColumn(name = "parent", updatable = true, nullable = false)
public ZoneEntity getParent() { ... }
}
在部署类型(Jboss-7.1.1)我得到以下异常:
Caused by: org.hibernate.MappingException: Could not determine type for: com.graphicreports.amun.habitat.ZoneEntity, at table: grDevices, for columns: [org.hibernate.mapping.Column(parent)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:304)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:288)
at org.hibernate.mapping.Property.isValid(Property.java:216)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:467)
是否需要在某处添加一些注释才能使其正常工作,或者我是否必须重新考虑我的数据库结构?
非常感谢史蒂夫