Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 323370 - flush() doesn't flush native queries if batch writing is enabled
Summary: flush() doesn't flush native queries if batch writing is enabled
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P2 major with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-23 05:07 EDT by Patric Rufflar CLA
Modified: 2022-06-09 10:32 EDT (History)
3 users (show)

See Also:


Attachments
proposed fix (1.92 KB, patch)
2010-10-13 14:07 EDT, Chris Delahunt CLA
no flags Details | Diff
proposed fix and test caes (7.34 KB, patch)
2010-10-18 15:57 EDT, Chris Delahunt CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Patric Rufflar CLA 2010-08-23 05:07:26 EDT
Build Identifier: 1.1.2.v20090612-r4475

It seems that if JDBC batch writing is enabled invoking flush() won't trigger the execution of "batched" native queries.

Although I only tested this against 1.1.2 it seems that the bug does still exist in 2.1 when looking at the responsible source code lines.

Reproducible: Always

Steps to Reproduce:
Steps to reproduce this:
0. enable batch writing in mode "JDBC"
1. create an EntityManager
2. create and execute a native query which consists of a simple insert
3. call flush() on the entity manager.

=> Nothing will be written to the database. It seems that the changes will only be persisted when commiting the transaction.
Comment 1 Patric Rufflar CLA 2010-08-24 12:10:52 EDT
Response on mailing list from James Sutherland:

It seems the batch is not being flushed because there were no changes, the
native query was thought to have already been executed.  Please log a bug
for this, the batch should always get flushed on flush, even with no
changes.

It is also odd that the native query is batched at all.  This seems to be
our default when batching, but can be set on the ModifyQuery using
setForceBatchStatementExecution(true).  There does not seem to be a query
hint for this though, so please add this to the bug.
Comment 2 Vicki Shimizu CLA 2010-09-13 09:48:54 EDT
See bug 266151. I need a way to get the correct number of rows processed from Query.executeUpdate(). I would either like a way to turn off batch writing for the
session or for the statement, so that I can get the actual number of rows
processed. If flush() is changed to execute the batched statement, it would give me a way to execute the batch immediately, however, I still wouldn't be able to get the count of rows processed.
Comment 3 Chris Delahunt CLA 2010-10-13 14:07:29 EDT
Created attachment 180808 [details]
proposed fix

uploaded patch corrects the flush to also flush the BatchWritingMechanism.  

bug 266151 (allowing executeUpdate to return an accurate row count when batch writing is used) will require new api to allow update statements to be included or excluded from batches, and likely make this fix unneccessary.  Please vote for it to have its priority adjusted.
Comment 4 Chris Delahunt CLA 2010-10-18 15:57:58 EDT
Created attachment 181128 [details]
proposed fix and test caes
Comment 5 Chris Delahunt CLA 2010-10-18 16:09:25 EDT
Fix checked into 2.2 revision 8372
-RepeatableWriteUnitOfWork now calls writesCompleted() on flush even when no changes in the changeset have been detected.
Comment 6 Eclipse Webmaster CLA 2022-06-09 10:32:56 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink