| Just setting a property causes an sql update [message #559187] |
Wed, 15 September 2010 17:06  |
Mauro Flores Messages: 83 Registered: September 2009 Location: Brasil |
Member |
|
|
If I set a property of an object inside a transactional context, an sql update is generated to that property. No merge is called.!!!
Is that a correct behavior?
Can I turn off this behavior?
em.getTransaction().begin();
AlunoED ed = em.find(AlunoED.class, 4492);
ed.setNomeAlu("Foo Boo Updated");
em.getTransaction().commit();
Log
[EL Fine]: 2010-09-15 18:01:26.343--Connection(367156)--UPDATE APM_ALUNO SET NOME_ALU = ? WHERE (NRO_INT_ALU = ?)
bind => [Foo Boo Updated, 4492]
|
|
|
| Re: Just setting a property causes an sql update [message #559428 is a reply to message #559187] |
Thu, 16 September 2010 11:11   |
James Sutherland Messages: 1834 Registered: July 2009 |
Senior Member |
|
|
This is how JPA is suppose to work.
merge() in JPA is just to merge detached objects (serialized), JPA always tracks changes to all managed objects, and merge is never required for managed objects.
If you do not want something updated, then do not change it. If you want a non-managed copy of an object you can read it through another EntityManager or do not commit the transaction. EclipseLink also provides a copy() API, or you could clone it yourself, or serialize it.
James : Wiki : Book : Blog
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06176 seconds