简体   繁体   中英

Interface between two related JPA entities

This is an extension of the following question

Interface between two related JPA entities

I have exactly the same scenario, but with one more addition.

To put it into the same example stated by #OpenSource , the Fax ans Email tables already extending from "Source" through InheritanceType as "Joined" which is another base class for many other classes. Now as in your example, you have made Fax and Email to extend from Channel which is specified with InheritanceType as TABLE_PER_CLASS.

I don't think I can implement the same approach (specifying TABLE_PER_CLASS) in my case as well. Please help me out to overcome this situation.

this is using ManyToAny mapping instead ManyToOne or OneToOne

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

    @Any(metaColumn = @Column(name = "type"))
    @AnyMetaDef(idType = "long", metaType = "string", 
            metaValues = { 
             @MetaValue(targetEntity = Fax.class, value = "fax"),
             @MetaValue(targetEntity = Email.class, value = "email"),
       })
    @JoinColumn(name="channelId")
    private Channel channel;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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