代码之家  ›  专栏  ›  技术社区  ›  jonua

如何从父模型继承e-bean模型而不创建父表?

  •  0
  • jonua  · 技术社区  · 9 年前

    我有一个抽象的父类 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 {}
    

    我想创建两个表: user book_author .模型表 不应创建。我该怎么做?

    1 回复  |  直到 9 年前
        1
  •  1
  •   chumakoff    9 年前

    EBean目前不支持表每类继承策略。看见 https://github.com/ebean-orm/ebean/issues/116 http://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 {...}
    
    推荐文章