I have two tables ... For example, a company and an employee (let it be very simple)
Company( id, name ); Employee( id, company_id );
Employee.company_id is a foreign key.
My model entity looks like this:
Employee
@ManyToOne(cascade = CascadeType.PERSIST) @JoinColumn(name = "company_id") Company company;
Company
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinColumn(name = "company_id") List<Employee> employeeList = new ArrayList<Employee>();
So yes, I want a list of employees for the company.
When I do the following ...
Employee e = new Employee(); e.setCompany(c); //c is an Company that is already in the database. DAO.insertEmployee(e); //this works fine!
If I receive an object of my company, the list is empty!
Ive tried endless different ways from the Hibernate documentation!
Obviously, I have not tried the right one yet!
I just want the list to be filled out for me or to find a reasonable alternative.
Help will be greatly appreciated, thanks!