-1

Am working on fetching the data from an third party API and then I want to insert those record in to Oracle database.This will occurs on hourly basis. Sometimes the API returns more than 50,000 records for an hour. So that time , it takes so much of time to insert the record(Absolutely record size too large). But I want to know is there any other way to increase the performance of the insert query.

Following is the code I used for inserting the records:

List<ClassName> retrievedList=util.getResultFromApi(); //The function getResultFromApi may returns more than 50,000 records.

userInfoRepository.save(retrievedList);

UserInfoRepository is my JpaRepository. Can anyone please help me with the suggestions.

kaviya .P
  • 469
  • 3
  • 11
  • 27

2 Answers2

0

You can make it faster, by calling flush() and clear() after a certain number of inserts.

int i = 0;
for(ClassName className: classNames) {
    dao.save(className);
    if(++i % 20 == 0) {
        dao.flushAndClear();
    }

}
Alien
  • 15,141
  • 6
  • 37
  • 57
0

Perhaps a relational database is not the best way to do it. If you are going more write hard to your database. May be Mongo could be a better choice.

CRISTIAN ROMERO MATESANZ
  • 1,502
  • 3
  • 14
  • 26