Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OptimisticLockException does not give any details if batch is active #1936

Merged
merged 5 commits into from
Oct 17, 2023

Conversation

vavishal
Copy link
Contributor

@vavishal vavishal commented Aug 31, 2023

When batch-writing is active and an OptimisticLockException appears then the message says "One or more objects cannot be updated because it has changed or been deleted since it was last read".
The above error message doesn't give details like which statement in batch execution has failed

So in the fix added parameters list which has failed for the SQL query during batch execution
Now the exception message will be as follows

"One or more objects of class org.eclipse.persistence.testing.tests.junit.optimisticlocking.Order with parameters list [[Order1-modified, 2, 1, 1]] cannot be updated for SQL query UPDATE ORDER_HEADER SET ORDERID = ?, TRANSACTIONCOUNT = ? WHERE ((ORDERKEY = ?) AND (TRANSACTIONCOUNT = ?)) because it has changed or been deleted since it was last read"

Added testcase at jpa/eclipselink.jpa.testapps/jpa.test.jpaadvancedproperties/src/test/java/org/eclipse/persistence/testing/tests/jpa/jpaadvancedproperties/OptimisticLockingBatchWritingTest.java

@pzygielo
Copy link

pzygielo commented Sep 4, 2023

What is Bugno35468915?

@vavishal vavishal changed the title Bugno35468915 - OptimisticLockException does not give any details if batch is active OptimisticLockException does not give any details if batch is active Sep 5, 2023
@vavishal
Copy link
Contributor Author

vavishal commented Sep 5, 2023

I have created a new issue at #1938 for which this PR is being raised

throw OptimisticLockException.batchStatementExecutionFailure();
Object object = null;
DatabaseQuery query = this.previousCall.getQuery();
if (query instanceof UpdateObjectQuery) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid instanceof and use appropriate isUpdate*Query method(s)

}
Object object = null;
DatabaseQuery query = this.previousCall.getQuery();
if (query instanceof UpdateObjectQuery) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dtto

return executeBatchRowCounts;
}

public void setExecuteBatchRowCounts(int[] rowCounts) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new methods should have some documentation

Assert.assertTrue(e.getMessage(),
e.getMessage().contains("One or more objects of class"));
Assert.assertTrue(e.getMessage(),
e.getMessage().contains("org.eclipse.persistence.testing.models.jpa.jpaadvancedproperties.Customer"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using Customer.class.getName() would be more friendly to possible refactoring

Copy link
Member

@lukasj lukasj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I do not think the test will pass on Oracle DB - can you test it there and share resutls, please?
  • new assertion can be probably added to existing test instead of adding whole new setup

@vavishal
Copy link
Contributor Author

I re-ran the tests using Oracle DB and it has passed successfully without any issues

So let me know if we can keep the new testcase at eclipselink/jpa/eclipselink.jpa.testapps/jpa.test.jpaadvancedproperties/src/test/java/org/eclipse/persistence/testing/tests/jpa/jpaadvancedproperties/OptimisticLockingBatchWritingTest.java or not

@lukasj lukasj merged commit ae7f32c into eclipse-ee4j:master Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants