我有两个班级Team和User:
@Entity
@Table(name = "team")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Team extends AbstractAuditingEntity implements Serializable, Participant {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;
和
@Entity
@Table(name = "user")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@org.springframework.data.elasticsearch.annotations.Document(indexName = "user")
public class User extends AbstractAuditingEntity implements Serializable, Participant {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;
我想创建新的实体匹配。比赛可以有2位参与者。参与者可以是团队或用户。我想创建抽象,以便我可以添加团队或用户以匹配参与者。我想创建Interface Participant并使用@MappedSuperclass进行映射,然后使用Team和User来实现Participant,但出现错误:
org.hibernate.AnnotationException:@OneToOne或@ManyToOne Match.participantFirst引用了一个未知实体:参与者
@MappedSuperclass
public interface Participant {
}
答案 0 :(得分:0)
有用的链接:Interfaces with hibernate annotations &http://docs.jboss.org/hibernate/core/3.3/reference/en/html/inheritance.html#inheritance-tableperconcrete
根据文档,使用XML映射可能会有所帮助,
If your superclass is abstract, map it with abstract="true". If it is not abstract, an additional table (it defaults to PAYMENT in the example above), is needed to hold instances of the superclass.