Community
Participate
Working Groups
In building a JPA 2.0 example I noticed some issues with the new ElementCollection mapping. On any commmit the version of the Employee object owning an ElementCollection or EmailAddress objects is always incremented, even though there was no change. This is due to the Employee emailAddress being a Map, and the change-set compare used in AggregateCollection always thinking everything changed for Map or Set. The change-set compare needs to use the same logic as the database commit. Also, with batch writing used, the Employee is not batched, as the Email is inserted one by one. The issues is that aggregate-collections are not deferred like direct-collection nor inserted like entity objects. Should be fixed to defer if the aggregate has no relationships (is simple). We should also do the same for multiple table descriptors if the target table has no relationships to it.
Also noticed in own table creation we do not create a constraint in the element collection tables (direct-collection, nor aggregate-collection). There is also no primary key constraint defined, but this may be ok (although we do create one on m-m's).
Ok, found a bigger issue, updates do not seem to work at all. Any ElementCollection used with weaving on (default) will fail any update. This is because aggregate-collections do not support change tracking, but the aggregate will default to using change tracking by default with weaving. Aggregate mappings fix this by making the aggregate descriptor inherit the source descriptor change tracking setting in postInitialize, but aggregate-collection is not doing this. The tests don't seem to find the issue as we seem to only have insert tests, no update tests. A workaround is to set @ChangeTracking(DEFFERED) in the Embedded class.
Created attachment 153752 [details] The patch suggested bu James (slightly simplified) and the test.
Created attachment 153755 [details] Take 2 - the patch originally suggested by James.
The above work around requires an EclipseLink specific annotation. There is also a workaround that does not require EclipseLink to be on the classpath to work (and is therefore JPA portable). In the persistence.xml file add the following property: <property name="eclipselink.weaving.changetracking" value="false" /> The disadvantage of this workaround vs the annotation one, is that deffered change tracking is put on the whole persistence unit, and may have an impact on performance.
*** Bug 296644 has been marked as a duplicate of this bug. ***
*** Bug 296880 has been marked as a duplicate of this bug. ***
Created attachment 153826 [details] patch - take 3 Updated the test - now it verifies both in cache and the data base, also tests updating of element collection member.
Setting target and priority. For information about the meanings of these fields see: http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Created attachment 153948 [details] patch take 4 - adds fix for collection mebers' updates. Mitesh found another issue that shows up when workaround applied and NPE is no longer thrown: collection members' updates don't show up in the database. That happens because of Eclipselink's optimization - weaving primary key into object - that is applied to Embeddable collection target class. Element collection of Embeddables is implemented in core by AggregateCollectionMapping, the target class reports all its attributes as components of primary key. When the object is created the woven pk is set, but when the object is altered the pk vowen pk is not updated - that's natural for entities where the pk is the real primary key, but that's not the case with AggregateCollection members - those can be altered during object's lifetime. The fix is not to weave aggregate collection descriptors. The patch also updates the test.
Checked into trunk (2.0.1). Reviewed by James.
Created attachment 154024 [details] Correction to the test - should make the test pass on server
Ported to 2.0.1. The bug is fixed in both trunk (2.1) and 2.0.1.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink