0

I'm writing a script to load records from a file in to a mysql DB using hibernate. I'm processing records in batches of 1000 using Transactions, an insert would fail if the record already exists in the DB, which would essentially make entire Transaction rolled back.Is there a way to know what are the records processed in rolled back transaction ?

Also, considering this scenario is there a better to way to do it ? Do note that the script runs daily and its not a one time loading and the file typically will have about 250 million records daily.

Aryan
  • 61
  • 2
  • 7

1 Answers1

0

You can use the StatelessSession API and check for a ConstraintViolationException; you can discard failure record without rollback transaction.

Luca Basso Ricci
  • 17,829
  • 2
  • 47
  • 69
  • I don't want to discard the failure record, I want the details to be saved to a file, hence I need a way to know which records are failed in the trasaction – Aryan Aug 06 '13 at 09:39
  • Check `ConstraintViolationException` and in catch-block log failed record. – Luca Basso Ricci Aug 06 '13 at 10:43