-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: HibernateException (Unexpected row count) on delete
PostPosted: Mon Dec 26, 2005 8:58 am 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
Hibernate version: 3.0

Hello everyone,

I'm facing a situation in which I get a HE on a delete. The delete does work, but when the transaction is flushed, there's an error.

Here's part of my log:

Code:
2005-12-26 10:18:54,669 DEBUG org.hibernate.SQL  -> delete from MPFICHATECNICA where mpFicha=?
Hibernate: delete from MPFICHATECNICA where mpFicha=?
2005-12-26 10:18:54,670 DEBUG hibernate.jdbc.AbstractBatcher  -> preparing statement
2005-12-26 10:18:54,672 DEBUG hibernate.type.IntegerType  -> binding '13' to parameter: 1
2005-12-26 10:18:54,683 ERROR event.def.AbstractFlushingEventListener  -> Could not synchronize database state with session
org.hibernate.HibernateException: Unexpected row count: 0 expected: 1
        at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:32)
        at org.hibernate.persister.entity.BasicEntityPersister.delete(BasicEntityPersister.java:2069)
        at org.hibernate.persister.entity.BasicEntityPersister.delete(BasicEntityPersister.java:2213)
        at org.hibernate.action.EntityDeleteAction.execute(EntityDeleteAction.java:59)
        at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
        at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
        at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
        at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
        at auge.conexao.MPFichaTecnicaService.delMPFichaTecnica(MPFichaTecnicaService.java:269)
        at auge.action.UpdDelMPFichaTecnicaAction.execute(UpdDelMPFichaTecnicaAction.java:101)


Here's the code of the delete method:
Code:
      Session session = ConnectionFactory.getInstance().getSession();
      Transaction t = null;
      try
      {
                        t = session.beginTransaction();
         session.delete(mpFichaTecnica);
         session.flush();
         t.commit();                       
      }
      catch (HibernateException he)
      {
                        if (t != null) {
                            t.rollback();
                        }
                        he.printStackTrace();
         throw he;
      }


And my mapping file:
Code:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
         "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
 
<hibernate-mapping>
    <class name="auge.bean.MPFichaTecnica" table="MPFICHATECNICA" >
          <id name="mpFicha" column="mpFicha" type="java.lang.Integer">
              <generator class="assigned"/>
          </id>
       <property name="quantidade" column="quantidade" type="java.lang.Integer" />                             
       <property name="principal" column="principal" type="java.lang.Integer" />                   

       <many-to-one name="cor" column="cor" class="auge.bean.Cor"
                    not-null="false" lazy="false" not-found="ignore"/>       
             
       <many-to-one name="fichaTecnica" column="fichaTecnica" class="auge.bean.FichaTecnica"
                    not-null="false" lazy="false" not-found="ignore"/>
                   
       <many-to-one name="materiaPrima" column="materia" class="auge.bean.MateriaPrima"
                    not-null="false" lazy="false" not-found="ignore"/>
                   
    </class>   
</hibernate-mapping>


Batching is disabled (my hibernate.jdbc.batch_size is 0)

Can anyone help?

Thanks

_________________
Don't forget to rate if the post helped!


Top
 Profile  
 
 Post subject: Optimistic lock error
PostPosted: Mon Dec 26, 2005 9:59 am 
Regular
Regular

Joined: Wed Dec 21, 2005 6:57 pm
Posts: 70
I beleive this *may* be a bug in Hibernate where the wrong exception is thrown upon Optimistic Lock failure. See my earlier post ( the "versioning/optimistic locking" item) in this page: http://hibernate.org/282.html

Hibernate checks optimistic locks by quering for the "right" version number of the row you are updating. If that Version + ID combo is not there, it gets zero rows, not one. This used to show up as "Unexpected row count" and I thought it would be fixed by now, but maybe not.

That is, this should throw an exception that indicates that there was an optimistic lock failure, and the object/id of the offending object.

Damon


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 26, 2005 12:11 pm 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
Hello,

I have updated my hibernate3.jar for the last jar of hibernate 3.1 available for download. Since the page says that the problem is only up to hibernate 3.0.2, this should have changed the exception, but it didn't.

The exception given is still the same.

Anyone?

Thanks

_________________
Don't forget to rate if the post helped!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 27, 2005 2:19 pm 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
This does not seem to be related to optimistic locks. The mapping file does have anything related to optimistic locks.

Are you sure this row existed in the database? Hibernate will throw this exception if you are trying to delete something which does not exists.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 27, 2005 6:04 pm 
Regular
Regular

Joined: Wed Dec 21, 2005 6:57 pm
Posts: 70
Check your SQL logging. It does indeed look like the SQL
delete from MPFICHATECNICA where mpFicha=? (13 bound)
is "expected" to return 1 row affected but is affecting 0 rows, indicating the item is not there. So see if the log 1) never inserted it or 2) deleted it earlier.

You may also check the Hibernate source code for the version you're using, and see what's going on at line 32 of NonBatchingBatcher, though abg1979 is right that the row seems not to exist.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.