我在映射@OneToOne 和在 jboss 下部署时遇到问题。
我有类的层次结构:
@Entity
@Table(name = "SEED")
@Inheritance
@DiscriminatorColumn(name = "ENTITY_TYPE")
@ForceDiscriminator
public class Parent implements Serializable
{
@Id
@SequenceGenerator(name = "SEED_SEQ", sequenceName = "SEED_SEQ")
@GeneratedValue(generator = "SEED_SEQ")
@Column(name = "AA_ID")
protected Long aaId;
@Column(name = "SECRET_SEED")
protected String seed;
@Column(name = "ENTITY_ID")
protected String entityId;
//getters and setters
}
@Entity
@DiscriminatorValue(value = "c1")
public class Child1 extends Parent
{
}
@Entity
@DiscriminatorValue(value = "c2")
public class Child2 extends Parent
{
}
我试图以这种方式映射子类:
@Entity
@Table(name = "CLINIC")
public class Clinic implements Serializable
{
@Id
@GeneratedValue(generator = "SEQ_CLINIC_RECID")
@SequenceGenerator(name = "SEQ_CLINIC_RECID", sequenceName = "SEQ_CLINIC_RECID")
@Column(name = "ID")
private Long id;
@Column(name = "CODE")
private String code;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CODE", referencedColumnName = "ENTITY_ID", insertable = false, updatable = false)
private Child1 child1;
//getters and setters
}
当我在 jboss-4.2.3.GA 上部署它时,出现以下异常:
org.hibernate.AnnotationException: referencedColumnNames(ENTITY_ID) of setup.entities.Clinic.child1 referencing setup.entities.Child1 not mapped to a single property
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:16
5)
at org.hibernate.cfg.FkSecondPass.doSecondPass(FkSecondPass.java:63)
at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:428)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.
java:286)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1233)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java
:154)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:869)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:407)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:126)
我使用休眠 3.2.6.ga,休眠实体管理器 3.3.1.ga。
为什么我会收到此错误?我的映射是否正确?