christian wrote:
This is NOT the right way to code ANY application. Do what the previous poster said, check for duplicate values before you try to save.
I have run into a similar problem for a valid use case, I believe.
If two independent sessions in two threads attempt to save an entity with the same natural key, an error message is always logged because of the log.error call in performExecutions.
Example:
Code:
thread 1 thread 2
start transaction
check for existence
start transaction
check for existence
save
commit transaction
save
commit transaction
In this scenarion, the commit in thread 1 will cause a ConstraintViolationException and it will always be logged as an error from AbstractFlushingEventListener.performExecutions.
I can deal with the exception, close the session and start a new one in thread 1 and then get the entity back saved by thread 2 and proceed normally, but that error message will be logged.
I assert that a log message at error level should not be logged unconditionally.
Perhaps it can be logged at debug, or a new configuration item could prevent logging that message or dictate what level to log it at?
The other possibility is that there is another way to do what I am trying to do that I am not aware of. I've searched the web and the forums here and did not find any solutions.