Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Set null causes the loading of the relationship
Set null causes the loading of the relationship [message #657472] Wed, 02 March 2011 16:38 Go to next message
Mauro Flores is currently offline Mauro Flores
Messages: 84
Registered: September 2009
Location: Brasil
Member
Why exactly when a lazy relationship property is set to null, the query to load that relationship is executed?

This happens just in JEE environment (weblogic 10.3.2 eclipselink 1.2.0)

Thanks. Mauro.
Re: Set null causes the loading of the relationship [message #657623 is a reply to message #657472] Thu, 03 March 2011 08:56 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Because the old value must be obtained.

To track changes and process the update correctly when you set the value of the relationship the old value must be known, to know if it changed or not. Also, if orphanRemoval is used the old value is required so it can be deleted.



James : Wiki : Book : Blog : Twitter
Re: Set null causes the loading of the relationship [message #659078 is a reply to message #657623] Thu, 10 March 2011 16:47 Go to previous messageGo to next message
Mauro Flores is currently offline Mauro Flores
Messages: 84
Registered: September 2009
Location: Brasil
Member
Is there a way to change this behaviour?

Is this behaviour correct even for detached entities ?

Thanks. Mauro.
Re: Set null causes the loading of the relationship [message #660811 is a reply to message #659078] Mon, 21 March 2011 13:14 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

If you read the objects using a read-only query, then they will not track changes (but you also must not change them). You could also set "eclipselink.maintain-cache" to false on a query, this would return detached objects.

You could also create a copy of the managed object using the JpaEntityManager copy() API.

How did you detach the object? If they were copied or serialized, then they will not query the old value. If they were read from another EntityManager, then they are probably still attached to it. Technically if you closed the EntityManager, EclipseLink could be smart enough to disable change tracking, but that is not currently done, you could log a bug for that if you wish.


James : Wiki : Book : Blog : Twitter
Previous Topic:How to choose sessions.xml
Next Topic:Changing container policy for toOne relationships
Goto Forum:
  


Current Time: Fri Aug 22 09:48:45 EDT 2014

Powered by FUDForum. Page generated in 0.06576 seconds