Hi,
I use the merge() procedure to create a new object in DB or update an existing object if it already exists. The problem arises when:
1. I merge an object which does not exist and supposed to be created
2. The object's entity hash two @Id fields, one of them is @ManyToOne reference.
After the merge():
1. All non-id fields are copied to the object returned by merge()
2. The object returned by merge is added to persistence context, and Hibernate tries to create it in DB at commit, but...
Both @Id fields of the object are nulls.
I use 3.6.3.Final
The code outline:
Code:
EntityManager em = ...;
IdObject idKey = em.find(IdObject.class, "someIdOfExistingObject");
assert idKey != null; // The first key part successfully loaded
SomeEntity entityKey = new SomeEntity(); // Create template object to copy from
entityKey.setId2("someId"); // Second key part
entityKey.setSomeField("12345"); // Some data to copy
entityKey.setIdObject(idKey); // First key part
SomeEntity o = em.merge(entityKey);
o.getSomeField(); => "12345", as expected
o.getId2(); => null!
o.getIdObject(); => null!
Is it normal? Or did I miss something?