Answer the question
In order to leave comments, you need to log in
Why is id not recorded at @OneToMany?
When I try to write a department with a filled employees collection, I get the saved Employee entities, but without a foreign key on the Department.
BUT, when I do a crutch, like: employee.setDartpent(department), I add employees to the collection, I get a foreign key on the department!
What could be my mistake? I would be grateful for any constructive suggestion. Maybe she will be my solution!
@Entity
class Department{
@Id
@GeneratedValue
private Integer id;
@OneToMany(mappedBy = "department",
cascade=CascadeType.ALL)
private List<Employee> employees= new ArrayList();
}
@Entity
class Employee{
@Id
@GeneratedValue
private Integer id;
@ManyToOne
@JoinColumn(name = "id_department")
private Department department;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question