带ID的嵌入式实体

时间:2013-03-31 17:03:53

标签: hibernate java-ee jboss7.x

我创建了一个抽象实体类,它定义了两个具体的子类:

@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)

是否需要添加一些注释才能使其工作,或者我是否需要重新考虑我的数据库结构?

非常感谢 史蒂夫

0 个答案:

没有答案