S
S
s2018-09-24 10:59:31
Java
s, 2018-09-24 10:59:31

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

1 answer(s)
S
s, 2018-09-24
@solovladys

Just informed that backbinding is mandatory in my case and as such there is no error.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question