Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » Just setting a property causes an sql update
Just setting a property causes an sql update [message #559187] Wed, 15 September 2010 17:06 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: Just setting a property causes an sql update [message #559490 is a reply to message #559428] Thu, 16 September 2010 15:30 Go to previous messageGo to next message
Eclipse UserFriend
James, thanks for explanation.

Two complementary questions:

1) The copy() melhod is available in eclipselink 1.2.1 ? I didn't find it in EntityManagerImpl

2)Instead of using one of your suggestions (copy, clone or serialization),
is a good approach to detach before making the set. Then sql update will be generated just when I call merge. The simple code below is an example of this approach that worked correctly:

    em.getTransaction().begin();
    AlunoED ed = em.find(AlunoED.class, 4492);
    org.eclipse.persistence.internal.jpa.EntityManagerImpl em2 = (org.eclipse.persistence.internal.jpa.EntityManagerImpl) em;
    em2.detach(ed);
    ed.setNomeAlu("Foo Boo Updated" + System.currentTimeMillis());    
    em.merge(ed);
    em.getTransaction().commit();
Re: Just setting a property causes an sql update [message #559954 is a reply to message #559187] Mon, 20 September 2010 10:20 Go to previous message
Eclipse UserFriend
copy() was added in 2.1.

In general if you don't want something updated it may be best just not to change it, or rollabck the transaction. Then you do not need to worry about detaching and merging.
Previous Topic:ANT Task Problem
Next Topic:EclipseLink Workbench source code?
Goto Forum:
  


Current Time: Wed Jul 23 10:12:23 EDT 2025

Powered by FUDForum. Page generated in 0.08316 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top