简体   繁体   中英

Play Framework 2 Ebean and InheritanceType as JOINED

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 ;)

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.

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;
...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM