I was facing a problem deleting entity read by hibernate. A simple call like load entity from database and immediately delete the entity without any change was failing with the exception
org.springframework.orm.hibernate4.HibernateOptimisticLockingFailureException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
I finally traced the error to an errant string which had following ascii characters - 239 (0xef), 191 (0xbf) and 189 (0xbd). After removing these characters, everything works properly. Since hibernate delete call matches all the fields in the where clause while deleting, call was failing when these characters are present in the string.
It seems like there is issue with character encoding in our setup somewhere as entities/columns returned by hibernate can not be used as part of where clause in criteria - or something is getting lost in translation.
What should I do - mysql setup or hibernate setup so that these issues can be avoided in future