0

I have a database which contains two tables (simplified) to a Session that contains Records, where one Session can contain somewhere between 1,000 and 10,000 records.

After receiving the Session data (with Records) and saving it in the database - which takes a total of 200ms when using the solution from my previous question from a year ago: JPA/Hibernate improve batch insert performance

which is good enough for the situation.

Now, after it has been saved I need to go through all the records and calculate values for two columns (these can't be calculated before Records have been saved).

When looping through all the records and saving each record - the process takes way too long (~30 records per second) making a 5000 record Session calculation take about 2 minutes.

Now, if I try to do the same thing as I did with insert and use a Hibernate Session to 'batch' the update - the data is calculated very quickly (20,000 rows per second) but the columns in the database are not updated with these new values.

Any ideas why the 'session trick' (described in my linked question) works very well for INSERT but fails silently for UPDATE queries? I'm not catching any exceptions and ignoring them, nor are there any exceptions being logged while this is running.

Community
  • 1
  • 1
Iv4n
  • 359
  • 1
  • 4
  • 18
  • Are you using the right method on the session? "save() and persist() result in an SQL INSERT, update() or merge() in an SQL UPDATE. Changes to persistent instances are detected at flush time and also result in an SQL UPDATE. saveOrUpdate() and replicate() result in either an INSERT or an UPDATE." (source: https://docs.jboss.org/hibernate/orm/4.2/javadocs/org/hibernate/Session.html) – gpgekko Aug 28 '14 at 11:20
  • Yes, I am using the 'update' method from the Session. I've also tried saveOrUpdate(). They all result in the data NOT being updated in the database. – Iv4n Aug 28 '14 at 15:07
  • You could try if using `merge` makes any difference, but beyond that I don't really have any other ideas... :/ – gpgekko Aug 29 '14 at 13:41

0 Answers0