I see exceptions in my project log and I cannot reproduce the problem.
This happens from time to time (not always) when I try to update the client using Hibernate. It seems, based on the information that is present in the logs, that hibernate calls the delete method on the update transaction .
Any idea on why this is happening?
Magazine
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();
return instance;
}
}
ClientsBL
public class ClientsBL {
public void updateClient(Client client) {
clientDAO.updatetx(client);
}
}
EDIT : Adding Multiple Mappings and Information:
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>
</class>
</hibernate-mapping>
Client.java has fields + getters + seters (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" />
</bean>
source
share