Hi, everybody!
I have some questions about the flowing code
Code:
@MappedSuperclass
public abstract class Work {
}
@Entity
public class CodeWork extends Work{
@OneToMany(mappedBy="codeWork")
private List<Employee> employees;
}
@Entity
public class UIWork extends Work{
@OneToMany(mappedBy="uiWork")
private List<Employee> employees;
}
@Entity
public class Employee{
@ManyToOne
@JoinColumn(name="codeWork_id", nullable=false, updatable= false)
private CodeWork codeWork;
@ManyToOne
@JoinColumn(name="uiWork_id", nullable=false, updatable= false)
private UIWork uiWork;
}
I think the code above can be optimized to this:
Code:
@MappedSuperclass
public abstract class Work {
@OneToMany(mappedBy="work")
private List<Employee> employees;
}
@Entity
public class CodeWork extends Work{
}
@Entity
public class UIWork extends Work{
}
@Entity
public class Employee{
@ManyToOne
@JoinColumn(name="work_id", nullable=false, updatable= false)
private Work work;
}
But after that, it will throw the org.hibernate.AnnotationException: @OneToOne or @ManyToOne on Employee.work references an unknown entity: Work.
I know the reason is that Work is not a Entity class. Could anyone explain me how to do this?
Thank you in advance.