Direct SQL import is duplicating the data as well as not setting up the association

I have a requirement to pull data from a external Legacy system database into my Domain model . I am facing two issues. I have created a microflow where I am using execute SQL widget to run my sql query in the external DB2 database and pull the required data. It works fine and stores the data in the expected persistent table . When I execute the microflow again it just duplicates the data whereas I would expect it either insert the new(delta) records or overwrite the existing records instead of duplicating it.  Second point is that I want to set the association correctly when I am importing external system data in my Mendix application tables but It is not doing that even though I have set the association correctly in my domain model. It is setting the associations for the records that are being created from the application.   Can anyone suggest how to address these two issues?
1 answers
  1. Since it is a microflow based activity, you must check with some unique identifiers to validate if that data exists already. Then use an update query, else do the insert query. 
  2. Probably check if you are committing it properly. 


Also refer: