Not sure. I tested with Core 3.3.2.GA, Annotations 3.4.0.GA and EntityManager 3.4.0.GA. Try to compare the below test code I did with what you have. Maybe it helps you find any misconfiguration :-)
Entities:
Code:
public class Company implements Serializable {
private static final long serialVersionUID = -4335199016164914319L;
@Column
private String name;
@Id
@GeneratedValue
@Column(name="CMP_COMPANY_ID")
private Long id;
// plus getter and setters
}
Code:
@Entity
@Table(name = "ITEMS")
public class Item implements Serializable {
private static final long serialVersionUID = 2544712122905762520L;
@EmbeddedId
public ItemPk itemPK;
@OneToMany(mappedBy = "manufItem")
private Set<ItemCrossReference> itemCrossReferences;
@Column(name = "ITM_ITEM_NAME")
private String itemName;
// plus getters and setters
}
Code:
@Entity
@Table(name = "ELC_REFERENCE")
public class ItemCrossReference implements Serializable {
private static final long serialVersionUID = -8140917261932033851L;
@Id
@GeneratedValue
private Long id;
@ManyToOne
@JoinColumns( {
@JoinColumn(name = "REF_MANUF_REF_CODE", referencedColumnName = "ITM_ITEM_CODE"),
@JoinColumn(name = "REF_MANUF_CMP_CODE", referencedColumnName = "ITM_COMP_ID") })
protected Item manufItem;
// plus getters and setters
}
Code:
@Embeddable
public class ItemPk implements Serializable {
private static final long serialVersionUID = -5892611455551220560L;
@ManyToOne
@JoinColumn(name = "ITM_COMP_ID", referencedColumnName = "CMP_COMPANY_ID")
protected Company company;
@Column(name = "ITM_ITEM_CODE", nullable = false)
private String itemCode;
// plus getters and setters
}
And this is the code for the test:
Code:
EntityManager em = getEntityManager();
em.getTransaction().begin();
Company company = new Company();
company.setName("ACME");
em.persist(company);
ItemPk pk = new ItemPk();
pk.setCompany(company);
pk.setItemCode("XYZ");
Item item = new Item();
item.setItemPK(pk);
item.setItemName("Item name 1");
em.persist(item);
em.getTransaction().commit();
em.getTransaction().begin();
ItemPk pk2 = new ItemPk();
pk2.setCompany(company);
pk2.setItemCode("ZYX");
ItemCrossReference xref = new ItemCrossReference();
xref.setManufItem(item);
Set<ItemCrossReference> xrefItems = new HashSet<ItemCrossReference>();
xrefItems.add(xref);
Item item2 = new Item();
item2.setItemPK(pk2);
item2.setItemName("Item name 2");
item2.setItemCrossReferences(xrefItems);
em.persist(item2);
em.getTransaction().commit();
em.close();