• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Batch update returned unexpected row

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am quite new to hibernate and have to make it work.

-------------------------------------------
Google said.
"Exception happens when deleting an object.
Solution
You tried to delete an object that was allready deleted from the database.

This can happen when cascading deletes where performed somewhere and you did not reattach your object. For deleting you do not nee to reattach your object but this could prevent this problem. "
-------------------------------------------
Code:

MyType something =
(MyType) session.get(
MyType.class, primaryKey);

.......
if something != null)
{
Transaction tx = session.beginTransaction();
session.delete(something);
tx.commit();
session.flush();
HibernateUtil.closeSession();

--------------------------------------------
Error:
org.hibernate.StaleStateException: Batch update returned unexpected row
count from update: 0 actual row count: 0 expected: 1 at org.hibernate.jdbc.
BatchingBatcher.checkRowCount(BatchingBatcher.java:92) at org.hibernate.jdbc
.BatchingBatcher.checkRowCounts(BatchingBatcher.java:78) at org.hibernate.
jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57) at org.
hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174) at org
.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226) 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
 
Lebing Xie
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, whole codes

public static final ThreadLocal session = new ThreadLocal();

Session s = (Session) session.get();

// Open a new Session, if this Thread has none yet
if (s == null)
{
s = sessionFactory.openSession();
session.set(s);
}

MyType something =
(MyType) s.get(
MyType.class, primaryKey);

.......
if (something != null)
{
Transaction tx = session.beginTransaction();
session.delete(something);
tx.commit(); // Error
session.flush();
HibernateUtil.closeSession();
 
Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic