Using an Entity (and their Primary Key) as another Entity's Id

前端 未结 1 743
执念已碎
执念已碎 2020-12-11 07:59

So, I\'m not sure how to ask this question, as it seems like it should be pretty easy to find the answer to this one.

I have 3 tables; ContentHeader, ContentType1 a

1条回答
  •  独厮守ぢ
    2020-12-11 08:18

    You can create a composite id class that only has the ContentHeader:

    @Embeddable
    public class ContentKey implements java.io.Serializable {
    
        @ManyToOne(cascade = {}, fetch = FetchType.LAZY)
        @JoinColumn(name = "ID", updatable = true)
        private ContentHeader header;
        // ...
    }
    
    @Entity
    @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
    public abstract class Content {
    
        @Id
        public ContentKey  getContentKeyId()
        // ...
    }
    

    That should do the trick.

    0 讨论(0)
提交回复
热议问题