-->
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.  [ 7 posts ] 
Author Message
 Post subject: Trying to delete/update already deleted object.
PostPosted: Fri Apr 16, 2004 10:47 am 
Newbie

Joined: Fri Apr 16, 2004 10:29 am
Posts: 3
Location: Gdansk
Hi,
Is there a hibernate exception which tells that object that i'm trying to delete/udapte is already deleted?
I've made several tests and exception i get is a HibernateException (not even JDBCException). The exact exception i get is
Code:
98627    [main      ] ERROR net.sf.hibernate.impl.SessionImpl - Could not synchronize database state with session
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
   at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
   at net.sf.hibernate.persister.EntityPersister.delete(EntityPersister.java:601)
   at net.sf.hibernate.impl.ScheduledDeletion.execute(ScheduledDeletion.java:29)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2385)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2343)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2207)
   at net.lidotech.biceps.dao.hib.Dao.delete(Dao.java:91)

I will not post hbm's or the full trace to the group because it's a general problem (i suppose ;-)).

thanks.

_________________
Best Regards.
Hytrus


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 16, 2004 11:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
No there is not, either catch the exception or try a load/get first.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 16, 2004 11:18 am 
Newbie

Joined: Fri Apr 16, 2004 10:29 am
Posts: 3
Location: Gdansk
michael wrote:
No there is not, either catch the exception or try a load/get first.


Thanks a lot Michael,

I've made a try with Session.refresh(Object) method, and this method throws the UnresolvableObjectException is there something against for delete or update methods to throw that exception??

The exception trace for refresh is
Code:
net.sf.hibernate.UnresolvableObjectException: No row with the given identifier exists: 29, of class: net.lidotech.biceps.domain.BcpsSystem
   at net.sf.hibernate.UnresolvableObjectException.throwIfNull(UnresolvableObjectException.java:38)
   at net.sf.hibernate.impl.SessionImpl.refresh(SessionImpl.java:2151)
   at net.sf.hibernate.impl.SessionImpl.refresh(SessionImpl.java:2113)
   at net.lidotech.biceps.dao.hib.Dao.refresh(Dao.java:524)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at org.springframework.aop.framework.AopProxyUtils.invokeJoinpointUsingReflection(AopProxyUtils.java:59)


Maybe that could be a good idea to add it to new version?
Thanks again.

_________________
Best Regards.
Hytrus


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 2:05 pm 
Newbie

Joined: Wed Apr 28, 2004 2:12 pm
Posts: 6
I've seen the same exception, even after doing the 'session.get()' and checking for null (which it isn't.) What's even worse is that this is a generic base class (DAO) for deleting objects. One of my objects deletes just fine, but another produces the 'Could not synchronize database state with session'... HibernateException: SQL insert, update or deletefailed (row not found).

Any idea(s)?

Delete method:

Code:
    public void delete(Object obj)
        throws SQLException, InvalidOperationException, ObjectNotFoundException
    {
        try {
            net.sf.hibernate.Session session = sessionFactory.openSession();
            session.connection().setCatalog(companyName);
            logger.debug("DELETE: connected to catalog " + session.connection().getCatalog());
            Transaction tx = null;
            Object found = null;
            try {
                if (null == (found = session.get(obj.getClass(), new Integer(((DBObject)obj).getID())))) {
                    throw new ObjectNotFoundException(getClass() + "#" + ((DBObject)obj).getID());
                }
                else {
                    tx = session.beginTransaction();
                    session.delete(found);
                    tx.commit();
                }
            }
            catch (HibernateException e) {
                logger.error("DELETE: Unhandled Exception: ", e);
                if (tx != null) {
                    tx.rollback();
                    logger.error("DELETE: rolled back transaction: " + tx);
                }
            }
            finally {
                session.close();
            }
        }
        catch (HibernateException e) {
            logger.error("DELETE: HibernateException: ", e);
            throw new InvalidOperationException(e);
        }
    }


And the mapping:
Code:

  <class name="Contact" table="CONTACT">
    <id name="ID" column="ID" unsaved-value="-1">
      <generator class="native"/>
    </id>
    <property name="address1"      column="address1"/>
    <property name="address2"      column="address2"/>
    <property name="city"          column="city"/>
    <property name="code"          column="code"/>
    <property name="companyName"   column="companyName"/>
    <property name="contactName"   column="contactName"/>
    <property name="country"       column="country"/>
    <property name="email1"        column="email1"/>
    <property name="email2"        column="email2"/>
    <property name="fax"           column="fax"/>
    <property name="name"          column="name"/>
    <property name="notes"         column="notes"/>
    <property name="phone1"        column="phone1"/>
    <property name="phone2"        column="phone2"/>
    <property name="state"         column="state"/>
    <property name="status"        column="status"/>
    <property name="url1"          column="url1"/>
    <property name="url2"          column="url2"/>
    <property name="zipCode"       column="zipCode"/>
  </class>

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 10:13 pm 
Newbie

Joined: Wed Apr 28, 2004 2:12 pm
Posts: 6
Found my own problem: It seems that there was a trigger on delete which was causing an exception in the Microsoft JDBC driver, which caused 0 rows to be deleted when Hibernate was expecting 1 (in addBatch(1)).

Tim


timlucia wrote:
I've seen the same exception, even after doing the 'session.get()' and checking for null (which it isn't.) What's even worse is that this is a generic base class (DAO) for deleting objects. One of my objects deletes just fine, but another produces the 'Could not synchronize database state with session'... HibernateException: SQL insert, update or deletefailed (row not found).

Any idea(s)?

Delete method:

Code:
    public void delete(Object obj)
        throws SQLException, InvalidOperationException, ObjectNotFoundException
    {
        try {
            net.sf.hibernate.Session session = sessionFactory.openSession();
            session.connection().setCatalog(companyName);
            logger.debug("DELETE: connected to catalog " + session.connection().getCatalog());
            Transaction tx = null;
            Object found = null;
            try {
                if (null == (found = session.get(obj.getClass(), new Integer(((DBObject)obj).getID())))) {
                    throw new ObjectNotFoundException(getClass() + "#" + ((DBObject)obj).getID());
                }
                else {
                    tx = session.beginTransaction();
                    session.delete(found);
                    tx.commit();
                }
            }
            catch (HibernateException e) {
                logger.error("DELETE: Unhandled Exception: ", e);
                if (tx != null) {
                    tx.rollback();
                    logger.error("DELETE: rolled back transaction: " + tx);
                }
            }
            finally {
                session.close();
            }
        }
        catch (HibernateException e) {
            logger.error("DELETE: HibernateException: ", e);
            throw new InvalidOperationException(e);
        }
    }


And the mapping:
Code:

  <class name="Contact" table="CONTACT">
    <id name="ID" column="ID" unsaved-value="-1">
      <generator class="native"/>
    </id>
    <property name="address1"      column="address1"/>
    <property name="address2"      column="address2"/>
    <property name="city"          column="city"/>
    <property name="code"          column="code"/>
    <property name="companyName"   column="companyName"/>
    <property name="contactName"   column="contactName"/>
    <property name="country"       column="country"/>
    <property name="email1"        column="email1"/>
    <property name="email2"        column="email2"/>
    <property name="fax"           column="fax"/>
    <property name="name"          column="name"/>
    <property name="notes"         column="notes"/>
    <property name="phone1"        column="phone1"/>
    <property name="phone2"        column="phone2"/>
    <property name="state"         column="state"/>
    <property name="status"        column="status"/>
    <property name="url1"          column="url1"/>
    <property name="url2"          column="url2"/>
    <property name="zipCode"       column="zipCode"/>
  </class>

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 24, 2004 9:49 am 
Newbie

Joined: Thu Jun 24, 2004 8:22 am
Posts: 7
Hi,

I don't know how you get these Exceptions after trying to update the deleted record, but with the version I'm using (2.1.4) I don't get any Exception; Hibernate simply does not execute the query when I commit my Transaction... Any ideas?

Thx
Johan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 24, 2004 10:08 am 
Newbie

Joined: Thu Jun 24, 2004 8:22 am
Posts: 7
Actually, I found out what was going on: apparently Hibernate does not try to update the entity, if no data has changed. This makes of course perfect sense...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.