We have an application that reads messages using JMS and commits them Sybase database. One of the table in the database has a trigger associated with it. The Trigger basically checks for some value based on a condition in inserted table and does something. below is the basic working of the trigger.
if (select count(*) from inserted where condition = condition1)>0 begin do something end
Now, when we are inserting/updating on this underlying table where the "condition1" happens to be something else that what the trigger is checking the returned rowcount is 0. While the hibernate that is inserting/updating into the database table is expecting rowcount to be 1 to complete its transaction. Hibernate encounters the following eror
"ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1"
and tries to rollback. but, the session doesn't have the transactional state to rollback. NOTE: the insert/update anyway happens.
When I try simulate this exception by processing the message from a file WITHOUT connecting to JMS, the exception doesn't seems to happen or at least I m seeing in the logs/console.
What I request to know from other experts are the following.
1. How to suppress the exception (as it anyway insert/updates the table)? 2. Is the JMS connection/session has something to do with hibernate session that I believe is hijacked by the trigger which causes the exception?
Disabling the trigger is not an option but, I m considering a different way to check within the trigger which would always return the number of record(s) inserted/updated would possible help this situation. I haven't yet tried out that but, I wanted to know some details on the above questions.
Any suggestions or pointer are welcome.
Rgds.
|