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