I have a scenario where my service layer gets called to do an update supplying a complete VO.
In some cases, depending on what values have changed I need to drive some processing.
So, my code retrieves the original VO from the database and does the comparisons.
Once all the attendant processing has been done, the code continues with the update.
However, the update fails with the exception
Code:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.usaa.wrkmgr.effort.publicapi.valueobject.EffortVO#211]
at org.hibernate.engine.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:613)
I can work around this by using an EJB call (with an associated new transaction) around the retrieval of the original data. I don't like this solution because its unneccesarily complex and I dont want the overhead of a new transaction every time I retrieve data.
Essentially, I need the retrieval of the original object to be a 'read only'. I considered a 'getForRead' style method with the DAO but I don't want my service layer to have to be aware of the peculiarities of my persistence layer.
Can anyone suggest a different way to solve this issue?