Creating an object and creating multiple associated objects inside a loop

0
Hi team,   I have a scenario where I’m getting list of data from an API.(List of Provinces and for each province its associated Holidays). I want to store the the Province and Holiday data in persistable entity. I created the domain model and of two entities (Province and Holiday) and associated many side to Holiday and one side to Province. But whenever I’m calling rest service and trying to store the Province and its associated Holidays inside a loop the Province objects are getting autocommited. I have used nested  loop to achieve this. I know its happening because I create Province object and then I iterate over holiday list (API data) then for each holiday list I create holiday (Persistable entity) object. And then add the holiday object to a list then commited the holiday list. But its not committing so not showing in the overview page of any of the entity.   I have attached screen shot of the domain model and microflow as well for reference. Need your help. Thanks Subhrajit.   Edit: I have added both the list before the main loop and committed the lists after that. Now it’s not auto committing but not storing the data in the database.(Attached the screenshot of updated microflow too)  
asked
2 answers
0

The reason for the autocommit is because you commit the holliday list first and since they are attached to a newProvince object that one is autocommitted. You should always commit the parent object first before you commit the child objects. And never try to commit inside iterations. Create two lists before the iteration (province and holidays) and after the iteration then commit the province list and then the holiday list both.

Regards,

Ronald

 

 

answered
0

Hi Subhrajit Pagal,

 

When you start the build-in DB viewer, do you see the records there? If so, the DataSource Microflow is not correct. Also, you could just retrieve the list from the database without an XPath...

 

 

Go Make It.

answered