java - @OneToMany mapping and creating JOIN table with same type entities fails with JPA -
i have employee
class. worker
class extends employee
, , leader
class extends worker
.
every leader
has list public list workersresponsiblefor = new arraylist<>();
. want create join table, illustrate if leader
responsible 1 or many workers
.
@entity @inheritance @discriminatorcolumn(name="emp_type") @table(name="employees") public abstract class employee implements printable, serializable { @id @generatedvalue @column(name = "employee_id", unique = true) private int id; @column(name = "position") @enumerated(enumtype.string) private position position; @column(name = "name") private string name; @column(name = "salary") private double salary; @transient public list<project> projectsworkingon = new arraylist<>(); public employee() { } }
worker
:
@entity public class worker extends employee { @id @generatedvalue @column(name = "worker_id", unique = true) private int id; public worker() { } }
leader
:
@entity public abstract class leader extends worker { public leader() { } public leader(position position, string name, double salary) { super(position, name, salary); } @onetomany @jointable(name="workers_responsible_for", joincolumns = {@joincolumn(name="responsible_for")}) public list<worker> workersresponsiblefor = new arraylist<>(); }
i'm sure, list annotations in leader
class wrong, because got lot of errors every time try make work. how can annotate properly, collect responsibilities new junction table?
Comments
Post a Comment