【问题标题】:How to inherit e-bean models from parent model without creating the parent table?如何在不创建父表的情况下从父模型继承 e-bean 模型?
【发布时间】:2016-12-18 12:52:55
【问题描述】:

我有一个抽象父类Person

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
abstract class Person extends Model {
    String firstName;
    String lastName;
    int gender;
}

还有两个子类,先继承:

@Entity
class User extends Person {}


@Entity
class BookAuthor extends Person {}

我想创建两个表:userbook_author。不应创建模型 Person 的表。我该怎么做?

【问题讨论】:

    标签: playframework-2.0 ebean


    【解决方案1】:

    EBean 目前不支持 TABLE PER CLASS 继承策略。见https://github.com/ebean-orm/ebean/issues/116http://ebean-orm.github.io/docs/mapping/jpa/

    你可以使用@MappedSuperclass注解。

    @MappedSuperclass
    abstract class Person extends Model {...}
    
    @Entity
    public class User extends Person {...}
    
    @Entity
    public class BookAuthor extends Person {...}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-08
      • 2016-05-27
      • 1970-01-01
      • 2015-11-25
      • 1970-01-01
      • 2021-07-30
      • 2019-12-26
      相关资源
      最近更新 更多