-->
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.  [ 9 posts ] 
Author Message
 Post subject: MS SQL 2000: delete() can't find rows
PostPosted: Fri Jul 09, 2004 10:42 am 
Newbie

Joined: Mon Nov 10, 2003 9:08 am
Posts: 12
I'm using MS's official JDBC driver with service pack 3, Hibernate 2.1.4, JDK 1.4.2_03 with J2EE 1.4 packages (javax). Microsoft SQL Server 2000.

Problem is that find() gives list of objects OK. When I iterate over that list and try to delete objects one by one (as simplest case), Hibernate immediately gives error:

Quote:
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:599)
at net.sf.hibernate.impl.ScheduledDeletion.execute(ScheduledDeletion.java:29)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2372)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)


This is what show_sql gives:

Quote:
Hibernate: delete from book where book_id=?


And using JDBC directly with "delete from book where book_id=123" works OK.


What could cause that problem? Both delete(String) and find()/delete(Object) give those errors. There is really a number of rows in the table.

Here is the code:
Code:
       Transaction t = hs.beginTransaction();
        try {
            hs.delete("FROM " + Book.class.getName() + " AS book");
            t.commit();
        } catch (Exception e) {
            e.printStackTrace();
            t.rollback();
        }


Here is the mapping:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="local">

    <class name="Book" table="book">

        <id name="id" column="book_id" type="java.lang.Long" unsaved-value="null">
            <generator class="identity"/>
        </id>

        <property name="title" column="title" not-null="true" type="string"/>

    </class>
   
</hibernate-mapping>



Any help appreciated,
Yuri


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 10:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Enable bind parameter locking - is the bound id value correct?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 10:54 am 
Beginner
Beginner

Joined: Mon May 17, 2004 7:15 am
Posts: 24
As I know, the HQL statement is case sensitive and the keyword should be lower case. But your code is:

Code:
     Transaction t = hs.beginTransaction();
        try {
            hs.delete([b]"FROM "[/b] + Book.class.getName() + " AS book");
            t.commit();
        } catch (Exception e) {
            e.printStackTrace();
            t.rollback();
        }


Hopefully it helps.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 10:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
No, not case sensitive. And the SQL query is generated correctly if you look at it. Must be either a problem with wrong bind parameter or wrong returned row count.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 11:04 am 
Newbie

Joined: Mon Nov 10, 2003 9:08 am
Posts: 12
Hibernate: delete from book where book_id=?
19:02:03,843 DEBUG LongType:46 - binding '35' to parameter: 1

ID 35 indeed exists in the table.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 11:37 am 
Newbie

Joined: Mon Nov 10, 2003 9:08 am
Posts: 12
Code:
        PreparedStatement st = conn.prepareStatement("DELETE FROM book WHERE book_id=?");
        st.setLong(1, 43);
        st.execute();


works all right. setString(1, "43") works as well.

But not with Hibernate. :-/


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 11:52 am 
Newbie

Joined: Mon Nov 10, 2003 9:08 am
Posts: 12
Problem persists when switching to JTDS driver (jtds.sf.net).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 12:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Do you have some triggers messing up the returned rowcount probably?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 13, 2004 2:58 am 
Newbie

Joined: Mon Nov 10, 2003 9:08 am
Posts: 12
Thanks, after removing all triggers that ERwin generated, Hibernate started to work like clock.

Cheers,
Yuri.


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