【问题标题】:How to create only subclasses tables in hibernate (@Transient @Entity)如何在休眠中仅创建子类表(@Transient @Entity)
【发布时间】:2017-03-03 06:32:18
【问题描述】:

我有一个超类模型

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class AbstractModel implements Model {
    @Id
    private UUID id;
}

还有一些继承者,比如 PostModel

@Entity
public class PostModel extends AbstractModel {
    private String header;
    private String content;
}

我只想在数据库中存储继承者,但所有继承者都应该在超类中声明相同的标识。是否可以不使用休眠继承为超类创建表?解决这个问题是正确的决定吗?谢谢。

【问题讨论】:

    标签: hibernate inheritance superclass transient


    【解决方案1】:

    将@MappedSuperclass 用于 AbstractModel(在您的情况下)。 看 https://docs.oracle.com/javaee/7/tutorial/persistence-intro002.htm 有关实体继承的更多信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-25
      • 1970-01-01
      • 1970-01-01
      • 2011-05-01
      • 1970-01-01
      • 2014-03-29
      • 2018-11-28
      相关资源
      最近更新 更多