cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to verify multiple records exist in the database or not in single database hit

Former Member
0 Kudos
539

Hi All,

We are getting multiple records as part of third-party SOAP API response, so I have to verify whether records exist in the database because invoking saveall() is throwing an exception if any record already exists in the database. So there should be two separate actions, one to insert the new record and second one to update existing records using current primary key against the record. Before splitting the records in the response into new and old records sets, I have check these records exist in the database or not. In this scenario, how do I verifying multiple records exist or not in the Database in a single hit than hitting databased for each record i.e. multiple times.

I really appreciate your help and support in advance

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Thanks Guys, I think getModelsByExample will help me to solve the senario.

Former Member
0 Kudos

Hi Rahul, thanks for your feedback, can I use this method to check multiple records in one hit or one by one?

pandeysuresh06
Participant
0 Kudos

Hi Sreejith , you can use flexibleSearchService.getModelsByExample(...) to check for multiple models. You can also refer link for the example for the same .

https://help.hybris.com/6.6.0/hcd/8c146aa686691014bbf6fe76a708ece2.html

pandeysuresh06
Participant
0 Kudos

Hi Sreejith,

I think you have to use the primary key of the item type like code to find whether data already exists for the item instance you are updating. Use flexible search query for the same.

rahulverma94
Active Participant
0 Kudos

Hi Sreejith,

You may use flexibleSearchService.getModelByExample() method to verify if the record already exists.

Regards Rahul

Former Member
0 Kudos

Hi Suresh, I do not have the primary key because records are coming third party API. So, how do I check multiple records of an item type exist in single database hit before store them using save all()? I.e. do not want to check records one by one

Cheers