• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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();
 
I'm doing laundry! Look how clean this tiny ad is:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic