Community
Participate
Working Groups
Build Identifier: Eclipse Persistence Services - 2.0.1.v20100213-r6600) This is a simple case where a performance setting unexpectedly changes application program logic. I am getting duplicate database inserts with @Entity public class MainEntity{ @OneToMany(fetch=FetchType.LAZY) private Set<ForeignEntity> foreigners; when I do mainEntity.getForeigners().add(foreigner); It works fine when I change to @OneToMany(fetch=FetchType.EAGER), or when I check with if(! foreigners.contains(foreigner)) before add(). It looks like add() is not fetching the lazy Set from the database. The attached testcase reproduces the behavior. Reproducible: Always Steps to Reproduce: Please refer to the attached testcase (NetBeans project)
Created attachment 178686 [details] Testcase: NetBeans Project in ZIP File
Created attachment 178710 [details] Standalone testcase - not using GlassFish container The attached testcase reproduces with weaving enabled.
Setting target and priority. See the following page for details of the meanings of these fields: http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Workaround: pass to createEMF method (or add to persistence.xml) property "eclipselink.weaving.changetracking" with value "false". Proposed solution: add a new PersistemnceUnitProperty to switch off IndirectCollections optimization, something like: "eclipselink.indirect-collection.avoid-instantiation" with values "true" - default and "false".
Deferring - did not make 2.1.2 cutoff and likely will not make 2.2 cutoff - for now, the workaround listed above can be used.
See also: Bug 331938 - likely related
The issue appears to be related to cascade persist. We do not actually get the Set itself wrong, but we cascade the persist before we check the list existence. This results in us trying to persist a new version of OfferRegion. Workaround is to avoid cascadePersist on the offer->offerRegion mapping.
Created attachment 197435 [details] proposed fix
Created attachment 197532 [details] updated patch
Too late for 2.3 check-in. Fix will appear in 2.3.1.
Created attachment 197538 [details] updated patch
Fix makes IndirectSet instantiate on add/remove by default and allows enable/disable of this functionality on IndirectSet and IndirectList. Reviewed by James Sutherland Added tests to: org.eclipse.persistence.testing.tests.jpa.inheritence.EntityManagerJUnitTestSuite Tested with Core and JPA LRG
Reopening. Still requires check-in to 2.3.1 stream when it opens.
Checked into 2.3.1
*** Bug 315040 has been marked as a duplicate of this bug. ***
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink