I was getting an error like this
a different object with the same identifier value was already associated with the session:
I've searched and found that it could be fixed with CascadeType.MERGE
or refactoring a lot of code to prevent that a same database object becomes two instances within the session.
I can't refactor it.
CascadeType.MERGE
worked, but that means I would have to code a lot to resolve remove problems, since it was .ALL
before, right?
I got it working putting
@Transactional(propagation = Propagation.REQUIRES_NEW)
above a method, of a class annoted with @Service
, that query database, which was the one that was throwing the exception I mentioned.
I need help to understand if this new annotated method can bring me any future headache like it is now.
It is being called from some cron jobs beside the action I'm fixing.