0

I have 40,000 records I need to insert into an Oracle database (12.2) using Spring Boot 2.3 and Spring Data JPA.

The input is read from a file then entity models are instantiated. I know for the fact that these 40k record might have existing data in the table (since there are several hundred millions already there).

I want to know if JPA would allow me to bulk insert the data, e.g. 500 at the time, and if a constraint violation occurs for any of the records, it should simply continue inserting the good ones (I do not want to merge to update if the record exists).

There is no time constraint on this as it only needs to be done once, and this is not a production data source. However, I prefer not to wait hours for the insertions to happen.

If I check for the existence of a record before inserting, e.g. existsMyEntityByPrimaryKeyColName(String primaryKey), it will take a while.

So basically, if an error occurs, the bulk insertion should insert the good records and leave the bad ones out (it would be great if I can get a list of these bad records but that's not a priority).

NuCradle
  • 665
  • 1
  • 9
  • 31
  • Whoever closed this question, the question is not answered in those topics. This is about avoiding roll back during bulk insertion with Spring Data "JPA", not just some low level Hibernate session management. – NuCradle Oct 16 '20 at 00:05
  • First, you need to google these kind of asks...The short answer is, it will roll back. JPA uses transaction management and session management, behind the scene. Do plain JDBC if you want to add your own logic. – z atef Oct 16 '20 at 01:54
  • What makes you think this wasn't looked up first before posting it here? From what you said it appears there is no way to accomplish this unless performing low level logic. Regardless, this does not warrant closing the question if the other questions do not answer a similar enquiry. Wouldn't you agree? – NuCradle Oct 16 '20 at 13:58

0 Answers0