Imagine an Employee Entity that references a Department using a Compound Key:
Code:
@Entity
public class Employee {
   ...
   @ManyToOne
   @JoinColumns({
      @JoinColumn(name="dept_country", referencedColumnName="country"),
      @JoinColumn(name="dept_id", referencedColumnName="id")
   })
   private Department dept;
   ...
In a Stateless Session Bean, I associate an Employee with a Department, by setting the appropriate attribute:
Code:
employee.setAbc(abc);
System.out.println(entityManager.contains(aDepartment)));  //true
employee.setDepartment(aDepartment);
employee.setXyz(xyz);
entityManager.merge(employee);
=> All attributes are correctly persisted (updated) into the database, 
except the Department is not associated with the Employee.
I wonder if this is related to the compound key, because when I look at the Hibernate SQL in the background, exactly those foreign key columns are missing.
Code:
14:46:18 INFO  [STDOUT#write] Hibernate:
14:46:18 INFO  [STDOUT#write]     update
14:46:18 INFO  [STDOUT#write]         employees
14:46:18 INFO  [STDOUT#write]     set
14:46:18 INFO  [STDOUT#write]         abc=?,
14:46:18 INFO  [STDOUT#write]         xyz=?,
14:46:18 INFO  [STDOUT#write]     where
14:46:18 INFO  [STDOUT#write]         id=?
I hope I missed something trivial...
PS: I asked the same question on 
StackOverflow.