Although I can see a lot of discussions around Hibernate and Batch Update, here is my specific scenario I hope to get comments from you all experts. I am iterating through a list of Document objects and for each of the document, I need to update a DOCUMENT_METADATA table with a property from Document object.
I can just use standard JDBC 2.0 Batch Update to do this. However, JDBC usage will be against the software standard in my place to use Hibernate throughout the application and I hate to make an exception.
In order to use Hibernate, I have to first fetch the DocumentMetadata object given the document ID from Document object I am iterating, set the DocumentMetadata property and then update the table.
I can do something like
for each document {
//fetch DocumentMetadata object given the id from Document
//invoke setter on DocumentMetadata object
em.persist(DocumentMetadata);
if (count % 50 == 0) {
em.flush(); //flush a batch of updates and release memory:
em.clear();
}
}
For n records ( I will be running around 10,000 records at a time), as the best case am I not doing n selects = 1 update with the Hibernate approach above? Given the size of my table (DOCUMENT_METADATA table has more than 100 columns and 1 million records), I fear I will run into performance issue comapred to JDBC approach.
ANy suggestions?
Thanks KOB