【问题标题】:JPA tables inheritance and object mappingJPA 表继承和对象映射
【发布时间】:2018-02-03 16:58:25
【问题描述】:

是否可以将 baseTable 与基类映射并告诉 JPA 工具不要在类中插入 baseTable 中的文件?

我在我的数据库的每个表中都有我想要的字段创建日期,所以我用该字段创建了一个 baseTable,其他表扩展了这个 baseTable。

当我生成用于映射此结构的类时,japtool 为我创建每个带有创建日期字段的表,显然我只希望在 baseEntity 类中而不是在每个子类中。

有办法实现吗?

【问题讨论】:

    标签: java jpa orm eclipselink


    【解决方案1】:

    如果我正确理解了您的答案,我认为您正在寻找JPA Inheritance

    @MappedSuperclass
    public class BaseEntity {
    @Id
        protected Integer id;
        protected Date createdDate;
        ...
    }
    @Entity
    public class EntityA extends BaseEntity {
       protected String otherAttribs;
       ...
    }
    @Entity
    public class EntityB extends BaseEntity {
       protected Float differentAttribs ;
       ...
    }
    

    【讨论】:

    • 谢谢@Andre,这正是我想要的
    • 嗨@AndreaScarafoni,我知道这是一个老问题,但如果它解决了您的问题,请将其标记为答案:)
    猜你喜欢
    • 2013-11-16
    • 2015-08-02
    • 2015-06-07
    • 2016-01-25
    • 2012-12-08
    • 2011-05-15
    • 1970-01-01
    • 2012-02-20
    • 1970-01-01
    相关资源
    最近更新 更多