This content has been marked as final.
Show 2 replies
-
1. Re: Enteties duplicated when merged
jsb Oct 12, 2005 12:03 PM (in response to kriwic)If I am reading the docs correctly, this may be by design.
From http://www.hibernate.org/hib_docs/entitymanager/reference/en/html/objectstate.html#d0e706:Merging vs. saveOrUpdate/saveOrUpdateCopy
Merging in EJB3 is similar to the saveOrUpdateCopy() method in native Hibernate. However, it is not the same as the saveOrUpdate() method, the given instance is not reattached with the persistence context, but a managed instance is returned by the merge() method.
I believe this means we end up with a detached, modified instance and a managed, merged instance. I could be wrong. I'm just beginning to scratch the surface of EJB3 and I believe that the docs I've found are still in "preview" state.
Hopefully someone authoritative can chime in?
Jonn -
2. Re: Enteties duplicated when merged
kriwic Oct 13, 2005 4:24 AM (in response to kriwic)Hi John and thanks for your answer.
I don't think it can be meant to work like this. Maybe you misunderstood my short description of the problem. I have created a test case that you can find at http://www.zert.se/ejb-test-20051013.zip.
The test creates an instance of ZVersion, modify it localy and then merge it.
Below is an extract of the test client:... ZRepository repository = (ZRepository) context.lookup(ZRepository.class.getName()); ZVersion v = repository.create(); v.addProperty("a").setValue("1"); v.addProperty("b").setValue("1"); v.addReference("a").setValue("1"); v.addReference("b").setValue("1"); System.out.println("pre update"); System.out.println("properties:"); for (ZProperty p: v.getProperties()) { System.out.println(p.getIdentifier() + " = " + p.getValue()); } System.out.println("references:"); for (ZReference r: v.getReferences()) { System.out.println(r.getIdentifier() + " = " + r.getValue()); } v = repository.update(v); System.out.println("\npost update"); System.out.println("properties:"); for (ZProperty p: v.getProperties()) { System.out.println(p.getIdentifier() + " = " + p.getValue()); } System.out.println("references:"); for (ZReference r: v.getReferences()) { System.out.println(r.getIdentifier() + " = " + r.getValue()); } v = repository.get(v.getId()); System.out.println("\npost get"); System.out.println("properties:"); for (ZProperty p: v.getProperties()) { System.out.println(p.getIdentifier() + " = " + p.getValue()); } System.out.println("references:"); for (ZReference r: v.getReferences()) { System.out.println(r.getIdentifier() + " = " + r.getValue()); } ...
The output is:pre update properties: a = 1 b = 1 references: a = 1 b = 1 post update properties: a = 1 b = 1 references: a = 1 b = 1 post get properties: a = 1 a = 1 b = 1 b = 1 references: a = 1 b = 1 a = 1 b = 1
I would however expect the output to be:pre update properties: a = 1 b = 1 references: a = 1 b = 1 post update properties: a = 1 b = 1 references: a = 1 b = 1 post get properties: a = 1 b = 1 references: a = 1 b = 1
/Krister