Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Generated SQL update statement is missing columns(Why is Eclipselink not including some changed entity fields in the SQL update statement?)
Generated SQL update statement is missing columns [message #727601] Wed, 21 September 2011 15:52 Go to next message
spockter is currently offline spockterFriend
Messages: 8
Registered: September 2011
Junior Member
I have a case where the SQL UPDATE statement generated by EclipseLink does not include all the entity members that have changed.

I first noticed the problem with a web page where some fields were not showing changes that had been made to them.

I recreated the problem in a single EJB startup method by
- finding the entity
- detaching the entity
- change 3 entity fields (all Strings)
- merge the entity and flush
- find the entity again

In the above case, the 2nd entity shows all field changes having been made. However, if I query the DB directly or rerun the program, it is evident that one of the fields was not updated.

The EclipseLink logged SQL UPDATE is missing one of the 3 fields.

Any suggestions why this might be happening?
Re: Generated SQL update statement is missing columns [message #727663 is a reply to message #727601] Wed, 21 September 2011 19:22 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello,

Is it always the same field? Is it included in the select when you initially call find? How is it mapped?

You can set logging to FINE or above to log the SQL using the <property name="eclipselink.logging.level" value="FINE"/> tag if it is not already showing.

Best Regards,
Chris
Re: Generated SQL update statement is missing columns [message #727773 is a reply to message #727663] Thu, 22 September 2011 00:18 Go to previous messageGo to next message
spockter is currently offline spockterFriend
Messages: 8
Registered: September 2011
Junior Member
Hi Chris

It is always the same fields that are excluded from the update.

These fields are mapped and are included in the SQL SELECT logged by EclipseLink, but are then excluded from the SQL UPDATE logged also by EclipseLink. It is as if EclipseLink has somehow not detected that the affected fields have changed.

Regards,
Mark
Re: Generated SQL update statement is missing columns [message #727784 is a reply to message #727663] Thu, 22 September 2011 00:18 Go to previous messageGo to next message
spockter is currently offline spockterFriend
Messages: 8
Registered: September 2011
Junior Member
Hi Chris

It is always the same fields that are excluded from the update.

These fields are mapped and are included in the SQL SELECT logged by EclipseLink, but are then excluded from the SQL UPDATE logged also by EclipseLink. It is as if EclipseLink has somehow not detected that the affected fields have changed.

Regards,
Mark
Re: Generated SQL update statement is missing columns [message #728107 is a reply to message #727773] Thu, 22 September 2011 14:33 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Please include your mappings for the class. Check if the columns have updatable=false.

It may also be related to change tracking, you could try setting the persistence unit property, "eclipseLink.weaving.changetracking"="false"


James : Wiki : Book : Blog : Twitter
(no subject) [message #728128 is a reply to message #727773] Thu, 22 September 2011 14:33 Go to previous messageGo to next message
James is currently offline JamesFriend
Messages: 272
Registered: July 2009
Senior Member
Please include your mappings for the class. Check if the columns have updatable=false.

It may also be related to change tracking, you could try setting the persistence unit property, "eclipseLink.weaving.changetracking"="false"
--
James : http://wiki.eclipse.org/EclipseLink : http://en.wikibooks.org/wiki/Java_Persistence : http://java-persistence-performance.blogspot.com/
Re: (no subject) [message #728905 is a reply to message #728128] Sat, 24 September 2011 10:07 Go to previous messageGo to next message
spockter is currently offline spockterFriend
Messages: 8
Registered: September 2011
Junior Member
Thanks for your suggestions, but I still have the problem.

The columns do not have updatable=false.
Setting "eclipseLink.weaving.changetracking"="false" made no difference either.

The class hierarchy is fairly involved, which is why I did not provide them in the first place. I have attempted to simplify it down to a smaller set of classes that could be shared and have had some surprising results.

What I have found is that I can enable or disable the error by including or excluding some lines of code in one of the entity methods. These entities have logic methods as well as the getter/setter methods. These logic methods are not invoked at all when the entity is simply being updated. Yet if I comment out certain lines of code in one of these methods, the entity update is successful - I can see the correct SQL update statement being generated.

The lines of code that seem to expose the error involve getting a dao object and calling a method on it. But as I have said, this method is not invoked when I test the entity update.

FYI, I am running Glassfish Open Source 3.1.1.

This application was working before (without this error) on Glassfish 3.

Mark
Re: (no subject) [message #729702 is a reply to message #728905] Mon, 26 September 2011 19:35 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Please include the code.

Do you have side-effects in your get/set methods?


James : Wiki : Book : Blog : Twitter
Re: (no subject) [message #731908 is a reply to message #729702] Mon, 03 October 2011 13:08 Go to previous message
spockter is currently offline spockterFriend
Messages: 8
Registered: September 2011
Junior Member
Sorry for the delay. I did not see your reply.

The get/set methods have no side effects. I have been using Lombok to generate them, but when this bug came up I coded the get/set methods directly for the affected fields, but that made no difference.

However, I have found a workaround. In the method containing the lines of code which brought on the error, there was a try catch block catching a javax.naming.NamingException. I removed the try catch and caught the exception at a higher level. That stopped the error.

As I have said, this method was not called at all in my testing, but it's presence in the entity class was causing EclipseLink to fail detection of a change to a field.

I'm satisfied this is a bug in the EclipseLink version in Glassfish 3.1.1. What I need to do is put together a simple reproducible test case that someone else can run to verify it.
Previous Topic:@Embeddable Inheritance
Next Topic:Why does @OrderBy add UPPER() to the ORDER BY clause?
Goto Forum:
  


Current Time: Fri Apr 19 04:52:24 GMT 2024

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

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

Back to the top