Imagine an object Employeethat is referenced Departmentusing a complex key :
@Entity
public class Employee {
...
@ManyToOne
@JoinColumns({
@JoinColumn(name="dept_country", referencedColumnName="country"),
@JoinColumn(name="dept_id", referencedColumnName="id")
})
private Department dept;
...
In a non-Bean session, I associate an employee with the department by setting the appropriate attribute:
employee.setAbc(abc);
System.out.println(entityManager.contains(aDepartment)));
employee.setDepartment(aDepartment);
employee.setXyz(xyz);
entityManager.merge(employee);
=> All attributes are correctly saved (updated) in the database, except for the Department .
I wonder if this is due to the composite key, because when I look at Hibernate SQL in the background, exactly such foreign key columns are missing.
14:46:18 INFO [STDOUT
14:46:18 INFO [STDOUT
14:46:18 INFO [STDOUT
14:46:18 INFO [STDOUT
14:46:18 INFO [STDOUT
14:46:18 INFO [STDOUT
14:46:18 INFO [STDOUT
14:46:18 INFO [STDOUT
Hope I missed something trivial ...
Jan source
share