Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate Batch Processing Using Native SQL
    primarykey
    data
    text
    <p>I have an application using hibernate. One of its modules calls a native SQL (StoredProc) in batch process. Roughly what it does is that every time it writes a file it updates a field in the database. Right now I am not sure how many files would need to be written as it is dependent on the number of transactions per day so it could be zero to a million. </p> <p>If I use this code snippet in while loop will I have any problems?</p> <pre><code>@Transactional public void test() { //The for loop represents a list of records that needs to be processed. for (int i = 0; i &lt; 1000000; i++ ) { //Process the records and write the information into a file. ... //Update a field(s) in the database using a stored procedure based on the processed information. updateField(String.valueOf(i)); } } @Transactional(propagation=propagation.MANDATORY) public void updateField(String value) { Session session = getSession(); SQLQuery sqlQuery = session.createSQLQuery("exec spUpdate :value"); sqlQuery.setParameter("value", value); sqlQuery.executeUpdate(); } </code></pre> <p>Will I need any other configurations for my data source and transaction manager?</p> <p>Will I need to set hibernate.jdbc.batch_size and hibernate.cache.use_second_level_cache?</p> <p>Will I need to use session flush and clear for this? The samples in the hibernate tutorial is using POJO's and not native sql so I am not sure if it is also applicable.</p> <p>Please note another part of the application is already using hibernate so as much as possible I would like to stick to using hibernate.</p> <p>Thank you for your time and I am hoping for your quick response. If it is also possible could code snippet would really be useful for me.</p> <hr> <p>Application Work Flow </p> <p>1) Query Database for the transaction information. (Transaction date, Type of account, currency, etc..)</p> <p>2) For each account process transaction information. (Discounts, Current Balance, etc..)</p> <p>3) Write the transaction information and processed information to a file.</p> <p>4) <strong>Update a database field based on the process information</strong></p> <p>5) Go back to step 2 while their are still accounts. (Assuming that no exception are thrown)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload