net.sf.hibernate.HibernateException: SQL update or deletion failed (row not found)

Hibernate JIRA | neil yang | 1 decade ago
  1. 0

    I have two class: Company & Person, they're Parent-children relation-ship. the 2 classes' id are all "assigned", beacause in an other true development env., I had to use programatic "assigned" id. When I run the test code, the exception thrown. package h; import java.util.ArrayList; import java.util.Date; public class Company { static int _lastID = 100; String id; public void setId(String value) { this.id=value; } public String getId() { return id; } String name; public void setName(String value) { this.name=value; } public String getName() { return name; } ArrayList partners = new ArrayList(); public String[] getMyPartners(){ return (String[])partners.toArray(new String[partners.size()]); } public void setMyPartners(String[] parts){ partners.clear(); for(int i=0; i<parts.length; i++){ partners.add(parts[i]); } } java.util.Date createdDate; public void setCreatedDate(Date d ){ this.createdDate = d; } public Date getCreatedDate(){ return this.createdDate; } java.util.List employees=new java.util.ArrayList(); public void setEmployees(java.util.List value) { this.employees=value; } public java.util.List getEmployees() { return employees; } public void addEmployee(h.Person value) { employees.add(value); } public void removeEmployee(h.Person value) { employees.remove(value); } public void clearEmployees() { employees.clear(); } private boolean _registered; public boolean getRegistered(){ return this._registered; } public void setRegistered(boolean val){ this._registered = val; } } Company.hbm.xml: <?xml version="1.0" encoding="GB2312"?> <!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" > <hibernate-mapping> <class name="h.Company"> <id name = "id" unsaved-value = "null"> <generator class="assigned"/> </id> <property name="name"/> <property name="myPartners" type="serializable" /> <property name="registered" type="boolean"/> <bag name="employees" cascade="all"> <key column="company_id"/> <one-to-many class="h.Person"/> </bag> </class> </hibernate-mapping> package h; import java.io.Serializable; public class Person implements Serializable{ public static int _lastID = 1000; String name; /** Sets the value of field name. @param name value of field name */ public void setName(String value) { this.name=value; } /** Gets the value of field name. @return value of field name */ public String getName() { return name; } String address; /** Sets the value of field address. @param address value of field address */ public void setAddress(String value) { this.address=value; } /** Gets the value of field address. @return value of field address */ public String getAddress() { return address; } String id ; /** Sets the value of field id. @param id value of field id */ public void setId(String value) { this.id=value; } /** Gets the value of field id. @return value of field id */ public String getId() { return id; } } Person.hbm.xml: <?xml version="1.0" encoding="GB2312"?> <!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" > <hibernate-mapping> <class name="h.Person"> <id name = "id" unsaved-value = "null"> <generator class="assigned"/> </id> <property name="name"/> <property name="address"/> </class> </hibernate-mapping> the Test code is: package h; import net.sf.hibernate.Session; import net.sf.hibernate.Transaction; import net.sf.hibernate.SessionFactory; import net.sf.hibernate.Query; import net.sf.hibernate.cfg.Configuration; import net.sf.hibernate.tool.hbm2ddl.SchemaExport; import java.util.List; import java.util.Iterator; class TestCompany { private static SessionFactory sessions; public static void main(String[] args) throws Exception { String[] partners = { "IBM", "Microsoft", "Lenovo", "Apple" }; Configuration conf = new Configuration() .addClass(Person.class) .addClass(Company.class); SchemaExport dbExport = new SchemaExport(conf); dbExport.setOutputFile("sql.txt"); dbExport.create(true, true); sessions = conf.buildSessionFactory(); //start...... Session s = sessions.openSession(); Transaction t = s.beginTransaction(); Company c = new Company(); c.setName("UFSoft Company Ltd."); c.setMyPartners(partners); c.setRegistered(true); Person p1 = new Person(); p1.setId(String.valueOf(Person._lastID++)); p1.setName("Liuto"); p1.setAddress("Beijing Haidian"); Person p2 = new Person(); p2.setId(String.valueOf(Person._lastID++)); p2.setName("sun"); p2.setAddress("beijing shangdi"); c.addEmployee(p1); c.addEmployee(p2); c.setId(String.valueOf(Company._lastID++)); //c.setId(Company._lastID++); s.save(c); s.flush(); t.commit(); s.close(); sessions.close(); } } when flush(), the bug reported: net.sf.hibernate.HibernateException: SQL update or deletion failed (row not found) at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25) at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:611) at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:580) at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:27) at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2073) at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2046) at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:1989) at h.TestCompany.main(TestCompany.java:115)

    Hibernate JIRA | 1 decade ago | neil yang
    net.sf.hibernate.HibernateException: SQL update or deletion failed (row not found)
  2. 0

    I have two class: Company & Person, they're Parent-children relation-ship. the 2 classes' id are all "assigned", beacause in an other true development env., I had to use programatic "assigned" id. When I run the test code, the exception thrown. package h; import java.util.ArrayList; import java.util.Date; public class Company { static int _lastID = 100; String id; public void setId(String value) { this.id=value; } public String getId() { return id; } String name; public void setName(String value) { this.name=value; } public String getName() { return name; } ArrayList partners = new ArrayList(); public String[] getMyPartners(){ return (String[])partners.toArray(new String[partners.size()]); } public void setMyPartners(String[] parts){ partners.clear(); for(int i=0; i<parts.length; i++){ partners.add(parts[i]); } } java.util.Date createdDate; public void setCreatedDate(Date d ){ this.createdDate = d; } public Date getCreatedDate(){ return this.createdDate; } java.util.List employees=new java.util.ArrayList(); public void setEmployees(java.util.List value) { this.employees=value; } public java.util.List getEmployees() { return employees; } public void addEmployee(h.Person value) { employees.add(value); } public void removeEmployee(h.Person value) { employees.remove(value); } public void clearEmployees() { employees.clear(); } private boolean _registered; public boolean getRegistered(){ return this._registered; } public void setRegistered(boolean val){ this._registered = val; } } Company.hbm.xml: <?xml version="1.0" encoding="GB2312"?> <!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" > <hibernate-mapping> <class name="h.Company"> <id name = "id" unsaved-value = "null"> <generator class="assigned"/> </id> <property name="name"/> <property name="myPartners" type="serializable" /> <property name="registered" type="boolean"/> <bag name="employees" cascade="all"> <key column="company_id"/> <one-to-many class="h.Person"/> </bag> </class> </hibernate-mapping> package h; import java.io.Serializable; public class Person implements Serializable{ public static int _lastID = 1000; String name; /** Sets the value of field name. @param name value of field name */ public void setName(String value) { this.name=value; } /** Gets the value of field name. @return value of field name */ public String getName() { return name; } String address; /** Sets the value of field address. @param address value of field address */ public void setAddress(String value) { this.address=value; } /** Gets the value of field address. @return value of field address */ public String getAddress() { return address; } String id ; /** Sets the value of field id. @param id value of field id */ public void setId(String value) { this.id=value; } /** Gets the value of field id. @return value of field id */ public String getId() { return id; } } Person.hbm.xml: <?xml version="1.0" encoding="GB2312"?> <!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" > <hibernate-mapping> <class name="h.Person"> <id name = "id" unsaved-value = "null"> <generator class="assigned"/> </id> <property name="name"/> <property name="address"/> </class> </hibernate-mapping> the Test code is: package h; import net.sf.hibernate.Session; import net.sf.hibernate.Transaction; import net.sf.hibernate.SessionFactory; import net.sf.hibernate.Query; import net.sf.hibernate.cfg.Configuration; import net.sf.hibernate.tool.hbm2ddl.SchemaExport; import java.util.List; import java.util.Iterator; class TestCompany { private static SessionFactory sessions; public static void main(String[] args) throws Exception { String[] partners = { "IBM", "Microsoft", "Lenovo", "Apple" }; Configuration conf = new Configuration() .addClass(Person.class) .addClass(Company.class); SchemaExport dbExport = new SchemaExport(conf); dbExport.setOutputFile("sql.txt"); dbExport.create(true, true); sessions = conf.buildSessionFactory(); //start...... Session s = sessions.openSession(); Transaction t = s.beginTransaction(); Company c = new Company(); c.setName("UFSoft Company Ltd."); c.setMyPartners(partners); c.setRegistered(true); Person p1 = new Person(); p1.setId(String.valueOf(Person._lastID++)); p1.setName("Liuto"); p1.setAddress("Beijing Haidian"); Person p2 = new Person(); p2.setId(String.valueOf(Person._lastID++)); p2.setName("sun"); p2.setAddress("beijing shangdi"); c.addEmployee(p1); c.addEmployee(p2); c.setId(String.valueOf(Company._lastID++)); //c.setId(Company._lastID++); s.save(c); s.flush(); t.commit(); s.close(); sessions.close(); } } when flush(), the bug reported: net.sf.hibernate.HibernateException: SQL update or deletion failed (row not found) at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25) at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:611) at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:580) at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:27) at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2073) at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2046) at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:1989) at h.TestCompany.main(TestCompany.java:115)

    Hibernate JIRA | 1 decade ago | neil yang
    net.sf.hibernate.HibernateException: SQL update or deletion failed (row not found)
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    Hibernate with relation one to many

    Google Groups | 1 decade ago | Pavel L.Yatsuk
    net.sf.hibernate.HibernateException: SQL update or deletion failed (row not foun d)

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. net.sf.hibernate.HibernateException

      SQL update or deletion failed (row not found)

      at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch()
    2. net.sf.hibernate
      SessionImpl.flush
      1. net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
      2. net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:611)
      3. net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:580)
      4. net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:27)
      5. net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2073)
      6. net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2046)
      7. net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:1989)
      7 frames
    3. h
      TestCompany.main
      1. h.TestCompany.main(TestCompany.java:115)
      1 frame