My application receives frequent remote events through a socket connection, each starting a new thread, and the subsequent actions often triggers the same object graph to be saved each time, with a single locked static session. But while that save executes, new updates are sometimes received which will add new elements to the same object graph. Which I believe is the reason for the exception:
TransientObjectException
object references an unsaved transient instance -
save the transient instance before flushing.
If that’s the reason, it’s understandable. But how I prevent this exception? If I let transaction Rollback, subsequent exceptions occur like StaleStateObject, then NonUniqueObjectException.
So how can this be handled or prevented?
Likely cause if this exception was that the entity collection was being modified while iterating over the collection during SaveOrUpdate (in different thread). So I believe locks must be placed to avoid these concurrent actions.