繁体   English   中英

两个相关的JPA实体之间的接口

[英]Interface between two related JPA entities

场景如下(表所示)

Delivery table
------
id  channelId   type
10  100         fax
20  200         email

Fax table
----
id   number
100  1234567
101  1234598

Email table
-----
id   email
200  a@a.com
201  b@b.com 

交付和渠道实体之间基本上是一对一的关系,但是由于每个具体渠道(传真,电子邮件)具有不同的成员,因此我想在两个实体之间创建通用接口(渠道)并将其用于@OneToOne关系。 在我看来,这是一个简单的场景,其中很多人可能已经经历了,但我无法成功。 我试着放那个targetEntity东西,但是没有用。 仍说“交货引用未知实体”

有任何想法吗? 提前致谢

Channel使用abstract超类和TABLE_PER_CLASS继承策略该怎么办? 像这样:

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Channel {
    @Id
    @GeneratedValue
    private Long id;

    // ...
}

@Entity
public class Fax extends Channel {
}

@Entity
public class Email extends Channel {
}

@Entity
public class Delivery {
    @Id
    @GeneratedValue
    private Long id;

    @OneToOne
    private Channel channel;

    // ...
}

暂无
暂无

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

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