Play Framework 2 Ebean and InheritanceType as JOINED

。_饼干妹妹 提交于 2019-12-08 16:35:31

问题


After some research on Google, I haven't found anyone who has my problem that's why I'm posting it here. In my application I have three entities : User (abstract), Customer, Agency. Customer and Agency extends User. Here is the code of User :

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class User extends AbstractModel {

    @Column(unique = true)
    @NotNull
    @Email
    public String email;

    @NotNull
    public String password;

}

The problem is that the generated schema creates only one table with the fields of User, Customer and Agency which is typically the behavior with InheritanceType.SINGLE_TABLE (default).

Is there any problem using Ebean and @Inheritance annotation ? I tried InheritanceType.TABLE_PER_CLASS, it didn't work either. I've never had this problem using JPA. Can anyone help ?

Thanks a lot ;)


回答1:


I read better the documentation of EBean and limitations : http://ebean-orm.github.io/docs/mapping/jpa/

Only Single Table Inheritance

Current there is only support for single table inheritance. The other two inheritance strategies are considered Enhancement requests and will be introduced in a feature release.




回答2:


If you just want an email and a password in your Customer and Agency tables, you could also take a look at the @Embedded / @Embeddable annotations:

@Embeddable
public class User  {

    @Column(unique = true)
    @NotNull
    @Email
    public String email;

    @NotNull
    public String password;

}

And the Customer class (similar for Agency):

@Entity
public class Customer  {

...

    @Embedded
    public User user;
...
}


来源:https://stackoverflow.com/questions/11872333/play-framework-2-ebean-and-inheritancetype-as-joined

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