I am loading list of tenders from text files (one tender one file) source and I would like to store it into database. I have tables address_point, street, city and country where address_point is refered from many tables (organization, tenders, ...).
When script is loading data and try save the same address in one transaction that fails with error - duplicate key.
For example scripts will add new tender and the tender is owned by new company. New tender and new company has same address and these two object are inserted in one transaction and both of them contains same address which city is already stored in the database so first I have to find this organization's city and replace it with found object or set primary key and do the same tender.
Next example script will add new tender and new organization with city which is not stored in the database alike I have to check whether the city is in the database or not. Next step is that I have to compare these two cities and make from them the one object if the cities are equal to avoid duplicate key.
But I have more than 3 refenreces to address points in one transactions from tender, organization, tour and so on. These two example are only for cities not for countries, regions, ... So making set of conditions is kind messy.
What is the most efficient ways how to solve this problem? I have defined isEqueal and hashCode but I have read that these methods are only for sets.