• Post Reply Bookmark Topic Watch Topic
  • New Topic

Batch update returned unexpected row

 
Lebing Xie
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
  • 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();
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!