使用@MappedSuperclass在Play中使用@ManyToOne获取错误

时间:2016-05-08 01:54:38

标签: java jpa playframework

我正在尝试在我们的项目中设置数据库。但是当我尝试在@MappedSuperclass实体上使用@ManyToOne和@ OneToMany时,我遇到了一些错误:

@MappedSuperclass
public abstract class Person extends Model{
//public abstract class Person {

    // ATTRIBUTES
    @Column(columnDefinition = "varchar(20) not null")
    private String firstName;
    @Column(columnDefinition = "varchar(20) not null")
    private String lastName;
    @Column(columnDefinition = "varchar(20) not null")
    private String password;
    @Column(columnDefinition = "varchar(50) not null")
    private String eMail;
    @Column(columnDefinition = "varchar(8) not null")
    private String svn;
    private static int staticId = 0;  // Identifier, staticId is unique.
    @Id
    @Column(columnDefinition = "integer not null")
    private int id;
    @Column(columnDefinition = "integer")
    private int age;
    @Column(columnDefinition = "varchar(10)")
    private String telephoneNumber;
    @Column(columnDefinition = "decimal(10,2)")
    private double salary;
    @Column(columnDefinition = "boolean")
    private boolean allowedOvertime;
    //@OneToMany(mappedBy = "person")
    private List<TimeEntryMonth> listTimeEntryMonth;
    @OneToMany(mappedBy = "person")
    private List<Vacation> listVacation;
    @OneToMany(mappedBy = "person")
    private List<SickLeave> listSickLeave; 

其中一个从Person扩展的类:

@Entity
public class Employee extends Person {

    // ATTRIBUTES
    private String position;
    private Boss boss;

其中一个@OneToMany关系:

public class SickLeave extends Model {

    /* ATTRIBUTES */
    @Id
    private int id;
    @ManyToOne
    private Person person;
    private int personIdSL;
    private String reason; 

如果我在没有@ManyToOne和@OneToMany的情况下编译我的整个项目,它将正常工作。但随着它将导致som错误:

  

注入构造函数时出错,java.lang.RuntimeException:读取错误   models.SickLeave

的注释

我试图删除摘要并用@Entity替换@MappedSuperclass并且该项目有效。所以我认为我不能在@MappedSuperclass上拥有@OneToMany和@ManyToOne关系,但我不想重构我的整个项目

有没有(更简单的)方法来处理这些问题?

谢谢。

1 个答案:

答案 0 :(得分:0)

Person不是Entity,因此您无法使用OneToMany。您需要Person Entity或指向Employee,这似乎对我更有意义。