I am seeing exceptions in my project log and I am not being able to reproduce the problem.
This is happening from time to time (not always) when I try to update a Client using Hibernate. It seems based on the info that is present in logs that hibernate is calling a delete method on an update transaction.
Any idea about why is this happening?
Log
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1 // Is this because the client has been deleted by hibernate?
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:85)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:70)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:47)
at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2707)
at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2911) // This is called by hibernate
at org.hibernate.action.EntityDeleteAction.execute(EntityDeleteAction.java:97)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:189)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
at com.project.dao.ClientDAO.updatetx(ClientDAO.java:138)
at com.project.bl.ClientsBL.updateClient(ClientsBL.java:2291) // This is the method I call
at [other non hibernate code]
ClientDAO
// ...
public class ClientDAO {
// ...
public Object updatetx(Object instance) throws Exception{
Session session = getSession();
Transaction tx = session.beginTransaction();
session.update(instance);
tx.commit(); // This is line ClientDAO.java:138
return instance;
}
// ...
}
ClientsBL
//..
public class ClientsBL {
// ...
public void updateClient(Client client) {
// ...
clientDAO.updatetx(client); // This is ClientsBL.java:2291
// ...
}
// ...
}
EDIT: adding some more mappings and info:
HBM:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.project.model.client.Client" table="CLIENT" dynamic-update="true">
<id name="clientId" type="java.lang.Long">
<column name="CLIENT_ID" />
<generator class="native" />
</id>
<property name="countryId" type="java.lang.Long">
<column name="COUNTRY_ID" />
</property>
<property name="name" type="string">
<column name="NAME" />
</property>
<!-- ... many other columns mapped in the same way -->
</class>
</hibernate-mapping>
Client.java just have fields+getters+setters (no annotations)
Spring:
<bean id="clientsBL"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref bean="clientsBLTarget" />
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_SUPPORTS,-Exception</prop>
</props>
</property>
</bean>
<bean id="clientsBLTarget"
class="com.project.bl.ClientsBL">
<property name="clientDAO"><ref bean="clientDAO" /></property>
<property name="clientDataDAO" ref="clientDataDAO" />
<!-- ... more DAOs -->
</bean>