Duplicate key error only if classes are woven [message #719050] |
Thu, 25 August 2011 18:24  |
Eclipse User |
|
|
|
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 (?, ?)")
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commitInternal(EntityTransactionImpl.java:102)
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:63)
Thanks,
Dave
|
|
|
Re: Duplicate key error only if classes are woven [message #720531 is a reply to message #719050] |
Tue, 30 August 2011 15:11  |
Eclipse User |
|
|
|
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).
"eclipselink.weaving.changetracking"="false"
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.
|
|
|
Powered by
FUDForum. Page generated in 0.24030 seconds