繁体   English   中英

休眠实体抽象

[英]Hibernate entities abstraction

我有两个班级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位参与者。 参与者可以是团队或用户。 我想创建抽象,以便我可以添加团队或用户以匹配参与者。 我想创建接口参与者并使用@MappedSuperclass进行映射,然后使用团队和用户来实现参与者,但是我遇到了错误:

org.hibernate.AnnotationException:Match.participant上的@OneToOne或@ManyToOne首先引用了一个未知实体:Participant

@MappedSuperclass
public interface Participant {

}

有用的链接: 具有休眠注释的接口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. 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM