|Duplicate key error only if classes are woven [message #719050]
||Thu, 25 August 2011 18:24
| Dave M
Registered: July 2009
I have a unidirectional one-to-many that is causing problems. It is mapped using a join table (since it's unidirectional). The instance variable in the entity is typed as a Set. I have verified that the equals and hashCode methods of the entity whose instances are stored in that Set are well-behaved (i.e., the state on which they are based is not mutated after insertion into the Set, etc.). And I have inspected the Set of the offending entity at runtime and I don't see any duplicates.|
The thing is....
When running with classes that have been statically woven I get the error shown below. When I turn weaving off the error no longer occurs.
Just wondering if anyone has an idea why that would be?
javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '3350-3379' for key 'PRIMARY'
Error Code: 1062
Call: INSERT INTO myschema.SUBGRAPH_MEMBERS (MEMBER_ID, SUBGRAPH_ID) VALUES (?, ?)
bind => [3379, 3350]
Query: DataModifyQuery(name="subgraphMembers" sql="INSERT INTO myschema.SUBGRAPH_MEMBERS (MEMBER_ID, SUBGRAPH_ID) VALUES (?, ?)")
|Re: Duplicate key error only if classes are woven [message #720531 is a reply to message #719050]
||Tue, 30 August 2011 15:11
| James Sutherland
Registered: July 2009
Location: Ottawa, Canada
There was an issue in EclipseLink that when change tracking is used, and calling add() on a lazy Set that had never been accessed, it would always try to add to the database, even if already contained in the Set.|
I think this was fixed in the latest release. So try the latest release, or log a bug (should already be a bug, so if you find it vote for it).
The workaround is to just disable weaving of change tracking (or weaving entirely).
Or you can disable change tracking for just the one descriptor using @ChangeTracking.
Or you could ensure you access the Set first before the add(), by calling contains() first.
James : Wiki : Book : Blog : Twitter
Powered by FUDForum
. Page generated in 0.02368 seconds