Extending an entity

点点圈 提交于 2019-12-05 11:19:16

With JPA, the default inheritance strategy (i.e. when not specified) is SINGLE_TABLE: there is only one table per inheritance hierarchy and all fields are persisted in the table of the base class.

If you want to have a table for each class in the inheritance hierarchy and each table to contain columns for all inherited fields, you need to use a TABLE_PER_CLASS strategy.

package foo.bar.framework;

@MappedSuperclass
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
abstract public class AbstractEntity {

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
    protected Long id;

    @Column(nullable = false)
    @Version
    protected Long consistencyVersion;

    ...
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!