Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Nulling an embedded object does not affect the database upon merge
Nulling an embedded object does not affect the database upon merge [message #1038948] Thu, 11 April 2013 14:38 Go to next message
Steven Van Impe is currently offline Steven Van Impe
Messages: 2
Registered: April 2013
Junior Member
I have the following classes:

@Entity
public class Reminder {

  private Location location;
  
  // other fields and methods
}


and

@Embeddable
public class Location {
  private double latitude;
  private double longitude;
  
  // no other fields here, just getters and setters


My database has a table REMINDER with columns LATITUDE and LONGITUDE to store the embedded field.

If I call someReminder.setLocation(someLocation), followed by em.merge(someReminder), the LATITUDE and LONGITUDE columns are filled in as expected. However, if I call someReminder.setLocation(null), followed by em.merge(someReminder), the LATITUDE and LONGITUDE columns are unchanged. Re-reading someReminder from the database gives back the previously stored location.

I am running on GlassFish 3.1.2.2 with EclipseLink 2.3.2.

And now for the strangest part:

If I run the exact same code on Java SE (with a different EntityManager and different transactions ofcourse, but using the same EclipseLink 2.3.2), I do get the expected results: the merge causes the columns LATITUDE and LONGITUDE to be nulled out.

Why isn't this working on Java EE ?
Re: Nulling an embedded object does not affect the database upon merge [message #1039904 is a reply to message #1038948] Fri, 12 April 2013 19:38 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1019
Registered: July 2009
Senior Member
Sounds like weaving might be a factor, assuming you didn't set up a java agent in the Java SE test as described here http://wiki.eclipse.org/EclipseLink/FAQ/JPA#How_to_disable_or_enable_weaving.3F

Weaving allows the use of attribute change tracking, which might be the cause of the issue, though I am just guessing. This can be tested directly by changing the weaving settings here:
http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving/Disabling_Weaving_with_Persistence_Unit_Properties

If you can reproduce this outside of glassfish, try using the latest EclipseLink version to see if its been fixed, and file a bug to have it resolved.

If that doesn't help track it down, try using a find followed by a refresh on the someReminder in the EntityManager before the merge with logging enabled.

Best Regards,
Chris

Re: Nulling an embedded object does not affect the database upon merge [message #1040442 is a reply to message #1039904] Sat, 13 April 2013 15:45 Go to previous messageGo to next message
Steven Van Impe is currently offline Steven Van Impe
Messages: 2
Registered: April 2013
Junior Member
Hi Chris,

Thanks for the tip. Turning off weaving solved the problem. Would you recommend I turn it off all the time ?
Re: Nulling an embedded object does not affect the database upon merge [message #1065935 is a reply to message #1040442] Fri, 28 June 2013 11:54 Go to previous messageGo to next message
Reiner Lott is currently offline Reiner Lott
Messages: 7
Registered: April 2013
Junior Member
Hi,

we have got a similar problem - disabled weaving solves the problem.

But what is the recommended way, enabled or disabled weaving?

Cheers,
Reiner
Re: Nulling an embedded object does not affect the database upon merge [message #1066637 is a reply to message #1065935] Wed, 03 July 2013 14:08 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Enabled weaving is recommend. Please log a bug for the issue (if it still occurs on 2.5), also ensure you don't have side-affects in your get/set methods that could be causing the issue.


James : Wiki : Book : Blog : Twitter
Previous Topic:missing Embeddable
Next Topic:JPQL Question - empty string
Goto Forum:
  


Current Time: Tue Sep 16 13:31:31 GMT 2014

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

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