I would like to avoid the situation where Hibernate's StaleObjectStateException with the message "Row was updated or deleted by another transaction" is thrown.
And I don't want to use the Pessimistic locking. To avoid it, I have thought about using Singleton EJB with Container Managed Transaction (CMT).
By default, Singleton EJB uses Container Managed Concurrency (CMC). Because of CMC, one usage of Singleton EJB is to ensure its methods locked with LockType.WRITE cannot be accessed concurrently from multiple threads.
So, if I have a method that is locked with LockType.WRITE and annotated with @AccessTimeout(value = n) and I perform DML operations within that method using CMT, I can avoid above mentioned Hibernate's issue.
I would appreciate your expert opinion in this matter.