I have two Classes Error and MainError (* - * association with MainError is the owner of the association)
I want to persist the data in my database and I cannot use Persist Cascade because I have many duplicate objects and I want to recognize the duplicate objects and associate them with the persisted ones (The name of Error and MainError is unique)
Error error1 = new Error ("ERR1");
Error error2 = new Error ("ERR2");
Error error3 = new Error ("ERR3");
Error error4 = new Error ("ERR4");
Error error5 = new Error ("ERR5");
Error error6 = new Error ("ERR1");
MainError mainError1 = new MainError("MAIN1");
MainError mainError2 = new MainError("MAIN2");
MainError mainError3 = new MainError("MAIN2");
mainError1.addError(error1);
mainError1.addError(error2);
mainError1.addError(error3);
mainError1.addError(error6);
mainError2.addError(error1);
mainError2.addError(error4);
mainError3.addError(error5);
//persisting Error and MainError
for example if I already persisted Error error1 = new Error ("ERR1") in my database and then I want to persist Error error6 = new Error ("ERR1"); I want that my application recognize that this is already persisted and associate "ERR1" to the corresponding MainError. I guess I will need to create a method findByName to know if the name of Error/MainError is already persisted and if so, returning this object, working with it and merge it ?
I hope that my question is not confusing Thank you very much