My problem is with individual objects ...
I am currently using Spring with Hibernate.
I have a display object that has a primary key as a string (I know that sucks ... but code refactoring will take several months) and I want to save it. (I simplified the object with only two attributes)
@Id private String id; private String pattern;
So, for example, I want to add something like:
["ID": "myFirstPattern", "template": "*"]
Please note that my primary key is already installed. The problem is that whenever I try to persist, Hibernate will try to associate this object with any object within the context (due to the primary key) and will not be able to do this because it is not there. Throwing an individual object error.
I did some research and came to the conclusion that merge () would satisfy my needs as it is saved and updated even if the object is not available. However, I found this a rather dirty workaround and wanted to check if there are any other solutions to this problem.
Note that we have a Helper layer, so the service level will not work directly with the HibernateDao level. Therefore, I can "mask" this by adding the "persist" and "update" methods, which will reference the same DAO merge method.
Thank you Flavio.
flavio_yama
source share