我正在尝试在子类中映射@Embeddable对象,其父类已经具有@Embeddable类型的字段。
休眠 Embeddable Objects文档 声明我可以使用@AttributeOverrides覆盖@Embeddable对象的列名:
例如
@Entity
public class Person implements Serializable {
// Persistent component using defaults
Address homeAddress;
@Embedded
@AttributeOverrides( {
@AttributeOverride(name="iso2", column = @Column(name="bornIso2") ),
@AttributeOverride(name="name", column = @Column(name="bornCountryName") )
} )
Country bornIn;
...
}
这是我的情况:
@Embeddable
public class ContentID implements Serializable {
@Column(name="contentID")
private String contentPath;
}
@MappedSuperclass
public abstract class BaseDomainObject implements Serializable {
@Embedded
private ContentID contentID;
}
public class Achievement extends BaseDomainObject {
@Embedded
@AttributeOverrides( {
@AttributeOverride(name="contentID", column = @Column(name="awardedItem") ),
} )
private ContentID awardedItem;
}
我得到的错误是:
org.hibernate.MappingException: 实体映射中的重复列: 成就栏:contentID(应该 用insert =“false”映射 更新=“假”) org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:652) 在 org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:674) 在 org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:670) 在 org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:696) 在 org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:450) 在 org.hibernate.mapping.SingleTableSubclass.validate(SingleTableSubclass.java:43) 在 org.hibernate.cfg.Configuration.validate(Configuration.java:1108) 在 org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1293) 在 org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
更新:
我查找了与此相关的Hibernate问题,GRAILS项目声称他们修复了这个问题但是他们的注释解决方案似乎不是有效的javax.persistence注释(也许它是一个新版本)。
JPA @ Embeddable / @ Embedded throws org.hibernate.MappingException:实体映射中的重复列