Bug 378908 - When a flush method is issued right after a remove method in a one-to-many relationship causes a SQLIntegrityConstraintViolationException.
Summary: When a flush method is issued right after a remove method in a one-to-many r...
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P2 major (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-08 17:02 EDT by Wai-Tak Wong CLA
Modified: 2022-06-09 10:10 EDT (History)
1 user (show)

See Also:


Attachments
A tar file for the Spring STS project that reproduces the issue (305.68 KB, application/x-zip-compressed)
2012-05-17 11:08 EDT, Wai-Tak Wong CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Wai-Tak Wong CLA 2012-05-08 17:02:36 EDT
Build Identifier: version:2.3.2 Build id:v20111125-r10461

For example, there are two entities: node and nodegroup. nodegroup and node have an one-to-many relationship. When a EntityManager flush method is issued right after the remove method, the eclipselink throws a java.sql.SQLIntegrityConstraintViolationException. If eclipselink 2.2.1 is used, there is no such error is reported.

As you can see the first line of the log, the remove() method has the Nodegroup associated. However, it throws the exception to complaint the nodegroup is associated in the internal update() call.
==================================================
[EL Finest]: 2012-05-08 16:02:56.996--UnitOfWork(848123013)--Thread(Thread[main,5,main])--remove() operation called on: Node[nodeId=105,nodes={[]},nodeGroupId=Nodegroup[nodes={[]},nodeGroupName=nodeGroupName_5,comment=comment_5,creatorId=5,creationTime=Tue May 08 16:13:59 EDT 2012,type=5,flags=5,nodeGroupId=97],proxyNodeId=persistence.jpa.entities.Node@557e5cbd,nodeName=nodeName_3,nodeAddress=nodeAddress_3,userName=userName_3,password=password_3,comment=comment_3,creatorId=3,creationTime=Tue May 08 16:16:49 EDT 2012,type=3,flags=3,features=3,hostId=hostId_3,policies={[]}]
16:02:56.997 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'transactionManager'
16:02:56.997 [main] DEBUG o.s.orm.jpa.JpaTransactionManager - Found thread-bound EntityManager [org.eclipse.persistence.internal.jpa.EntityManagerImpl@788bf135] for JPA transaction
16:02:56.997 [main] DEBUG o.s.orm.jpa.JpaTransactionManager - Participating in existing transaction
[EL Finer]: 2012-05-08 16:02:56.998--UnitOfWork(848123013)--Thread(Thread[main,5,main])--begin unit of work flush
[EL Finest]: 2012-05-08 16:02:57.002--UnitOfWork(848123013)--Thread(Thread[main,5,main])--Execute query DataModifyQuery(name="policies" )
[EL Fine]: 2012-05-08 16:02:57.002--ClientSession(730401895)--Connection(93216445)--Thread(Thread[main,5,main])--DELETE FROM nodepolicy WHERE (nodeID = ?)
	bind => [105]
[EL Finest]: 2012-05-08 16:02:57.012--ClientSession(730401895)--Connection(93216445)--Thread(Thread[main,5,main])--No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table.:02000 - null
[EL Finest]: 2012-05-08 16:02:57.013--UnitOfWork(848123013)--Thread(Thread[main,5,main])--Execute query DeleteObjectQuery(Node[nodeId=105,nodes={[]},nodeGroupId=Nodegroup[nodes={[]},nodeGroupName=nodeGroupName_5,comment=comment_5,creatorId=5,creationTime=Tue May 08 16:13:59 EDT 2012,type=5,flags=5,nodeGroupId=97],proxyNodeId=persistence.jpa.entities.Node@557e5cbd,nodeName=nodeName_3,nodeAddress=nodeAddress_3,userName=userName_3,password=password_3,comment=comment_3,creatorId=3,creationTime=Tue May 08 16:16:49 EDT 2012,type=3,flags=3,features=3,hostId=hostId_3,policies={[]}])
[EL Finest]: 2012-05-08 16:02:57.013--UnitOfWork(848123013)--Thread(Thread[main,5,main])--Execute query DeleteObjectQuery(Node[nodeId=105,nodes={[]},nodeGroupId=Nodegroup[nodes={[]},nodeGroupName=nodeGroupName_5,comment=comment_5,creatorId=5,creationTime=Tue May 08 16:13:59 EDT 2012,type=5,flags=5,nodeGroupId=97],proxyNodeId=persistence.jpa.entities.Node@557e5cbd,nodeName=nodeName_3,nodeAddress=nodeAddress_3,userName=userName_3,password=password_3,comment=comment_3,creatorId=3,creationTime=Tue May 08 16:16:49 EDT 2012,type=3,flags=3,features=3,hostId=hostId_3,policies={[]}])
[EL Fine]: 2012-05-08 16:02:57.014--ClientSession(730401895)--Connection(93216445)--Thread(Thread[main,5,main])--UPDATE node SET nodeGroupID = ? WHERE (nodeID = ?)
	bind => [null, 105]
[EL Fine]: 2012-05-08 16:02:57.025--ClientSession(730401895)--Thread(Thread[main,5,main])--VALUES(1)
[EL Warning]: 2012-05-08 16:02:57.026--UnitOfWork(848123013)--Thread(Thread[main,5,main])--Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: Column 'NODEGROUPID'  cannot accept a NULL value.
Error Code: 20000
Call: UPDATE node SET nodeGroupID = ? WHERE (nodeID = ?)
	bind => [null, 105]
Query: DeleteObjectQuery(Node[nodeId=105,nodes={[]},nodeGroupId=Nodegroup[nodes={[]},nodeGroupName=nodeGroupName_5,comment=comment_5,creatorId=5,creationTime=Tue May 08 16:13:59 EDT 2012,type=5,flags=5,nodeGroupId=97],proxyNodeId=persistence.jpa.entities.Node@557e5cbd,nodeName=nodeName_3,nodeAddress=nodeAddress_3,userName=userName_3,password=password_3,comment=comment_3,creatorId=3,creationTime=Tue May 08 16:16:49 EDT 2012,type=3,flags=3,features=3,hostId=hostId_3,policies={[]}])
	at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)
====================================================================

Reproducible: Always

Steps to Reproduce:
always reproduce with our current codes.
Comment 1 Tom Ware CLA 2012-05-15 11:50:23 EDT
Please provide code to reproduce the problem.
Comment 2 Tom Ware CLA 2012-05-15 11:54:49 EDT
Possibly related to:  https://bugs.eclipse.org/bugs/show_bug.cgi?id=341709
Comment 3 Wai-Tak Wong CLA 2012-05-17 10:05:54 EDT
(In reply to comment #2)
> Possibly related to:  https://bugs.eclipse.org/bugs/show_bug.cgi?id=341709

I am going to produce a simple case right now and send you the codes later.
Thanks.
Comment 4 Wai-Tak Wong CLA 2012-05-17 11:08:34 EDT
Created attachment 215783 [details]
A tar file for the Spring STS project that reproduces the issue

Please extract STS project from the tar.zip file.
Then run the (maven) mvn test.
The eclipselink debug has been turned on.
The testremove() method gets failure for the case.
You will see the issues.
Check the log file under target/surefire-reports directory.
The log file name is persistence.jpa.entities.NodeIntegrationTest-output.txt.
Comment 5 Tom Ware CLA 2012-06-08 09:30:11 EDT
FYI: 341709 is now fixed in 2.4.0.  Can you please try the latest 2.4 build and see if you still have the issue. (note, for the fix to work, you will have to specify that any columns with non null constraints are non null in your JPA metadata)
Comment 6 Eclipse Webmaster CLA 2022-06-09 10:10:40 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink