Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 219
c4k Avatar asked Aug 08 '12 20:08

c4k


2 Answers

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.

like image 135
c4k Avatar answered Oct 21 '22 04:10

c4k


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;
...
}
like image 35
ndeverge Avatar answered Oct 21 '22 04:10

ndeverge