Announcement Announcement Module
Collapse
No announcement yet.
hibernateTemplate.execute(callback) throws HibernateOptimisticLockingFailureException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • hibernateTemplate.execute(callback) throws HibernateOptimisticLockingFailureException

    Hi Friends,

    When trying to do a simple insert into a table in HSQL DB using Spring 2.5 & Hibernate 3.2 I'm getting HibernateOptimisticLockingFailureException.

    My code is as below:

    1) In my DAO class:
    public void saveOrUpdate(final Products products){

    HibernateCallback callback = new HibernateCallback() {
    public Object doInHibernate(Session session)
    throws HibernateException,SQLException {
    session.saveOrUpdate(products);
    return null;
    }
    };
    hibernateTemplate.execute(callback);
    }

    // The error comes in hibernateTemplate.execute(callback);

    2) My hibernate mapping file Products.hbm.xml is as follows:

    <?xml version="1.0"?>

    <!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

    <hibernate-mapping>
    <class
    name="springapp.hibernateExample.Products"
    table="Products" lazy="false">

    <id name="id"
    column="id"
    type="string"
    unsaved-value="0" >
    <generator class="native">
    </generator>
    </id>

    <property
    name="description"
    type="string"
    update="true"
    insert="true"
    column="description"
    length="255" />

    <property
    name="price"
    type="double"
    update="true"
    insert="true"
    column="price" />
    </class>
    </hibernate-mapping>

    3) The exception I'm getting is as follows:

    Oct 1, 2009 7:57:11 AM org.hibernate.jdbc.BatchingBatcher doExecuteBatch
    SEVERE: Exception executing batch:
    org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
    at org.hibernate.jdbc.Expectations$BasicExpectation.c heckBatched(Expectations.java:85)
    at org.hibernate.jdbc.Expectations$BasicExpectation.v erifyOutcome(Expectations.java:70)
    at org.hibernate.jdbc.BatchingBatcher.checkRowCounts( BatchingBatcher.java:90)
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch( BatchingBatcher.java:70)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(Ab stractBatcher.java:268)
    at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:266)
    at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:168)
    at org.hibernate.event.def.AbstractFlushingEventListe ner.performExecutions(AbstractFlushingEventListene r.java:321)
    at org.hibernate.event.def.DefaultFlushEventListener. onFlush(DefaultFlushEventListener.java:50)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.j ava:1028)
    at org.springframework.orm.hibernate3.HibernateAccess or.flushIfNecessary(HibernateAccessor.java:390)
    at org.springframework.orm.hibernate3.HibernateTempla te.doExecute(HibernateTemplate.java:420)
    at org.springframework.orm.hibernate3.HibernateTempla te.execute(HibernateTemplate.java:339)
    at springapp.hibernateExample.ProductsDao.saveOrUpdat e(ProductsDao.java:72)
    at springapp.hibernateExample.SpringHibernateTest.mai n(SpringHibernateTest.java:20)
    Oct 1, 2009 7:57:11 AM org.hibernate.event.def.AbstractFlushingEventListe ner performExecutions
    SEVERE: Could not synchronize database state with session
    org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
    at org.hibernate.jdbc.Expectations$BasicExpectation.c heckBatched(Expectations.java:85)
    at org.hibernate.jdbc.Expectations$BasicExpectation.v erifyOutcome(Expectations.java:70)
    at org.hibernate.jdbc.BatchingBatcher.checkRowCounts( BatchingBatcher.java:90)
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch( BatchingBatcher.java:70)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(Ab stractBatcher.java:268)
    at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:266)
    at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:168)
    at org.hibernate.event.def.AbstractFlushingEventListe ner.performExecutions(AbstractFlushingEventListene r.java:321)
    at org.hibernate.event.def.DefaultFlushEventListener. onFlush(DefaultFlushEventListener.java:50)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.j ava:1028)
    at org.springframework.orm.hibernate3.HibernateAccess or.flushIfNecessary(HibernateAccessor.java:390)
    at org.springframework.orm.hibernate3.HibernateTempla te.doExecute(HibernateTemplate.java:420)
    at org.springframework.orm.hibernate3.HibernateTempla te.execute(HibernateTemplate.java:339)
    at springapp.hibernateExample.ProductsDao.saveOrUpdat e(ProductsDao.java:72)
    at springapp.hibernateExample.SpringHibernateTest.mai n(SpringHibernateTest.java:20)
    Exception in thread "main" org.springframework.orm.hibernate3.HibernateOptimi sticLockingFailureException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
    at org.springframework.orm.hibernate3.SessionFactoryU tils.convertHibernateAccessException(SessionFactor yUtils.java:672)
    at org.springframework.orm.hibernate3.HibernateAccess or.convertHibernateAccessException(HibernateAccess or.java:412)
    at org.springframework.orm.hibernate3.HibernateTempla te.doExecute(HibernateTemplate.java:424)
    at org.springframework.orm.hibernate3.HibernateTempla te.execute(HibernateTemplate.java:339)
    at springapp.hibernateExample.ProductsDao.saveOrUpdat e(ProductsDao.java:72)
    at springapp.hibernateExample.SpringHibernateTest.mai n(SpringHibernateTest.java:20)
    Caused by: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
    at org.hibernate.jdbc.Expectations$BasicExpectation.c heckBatched(Expectations.java:85)
    at org.hibernate.jdbc.Expectations$BasicExpectation.v erifyOutcome(Expectations.java:70)
    at org.hibernate.jdbc.BatchingBatcher.checkRowCounts( BatchingBatcher.java:90)
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch( BatchingBatcher.java:70)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(Ab stractBatcher.java:268)
    at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:266)
    at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:168)
    at org.hibernate.event.def.AbstractFlushingEventListe ner.performExecutions(AbstractFlushingEventListene r.java:321)
    at org.hibernate.event.def.DefaultFlushEventListener. onFlush(DefaultFlushEventListener.java:50)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.j ava:1028)
    at org.springframework.orm.hibernate3.HibernateAccess or.flushIfNecessary(HibernateAccessor.java:390)
    at org.springframework.orm.hibernate3.HibernateTempla te.doExecute(HibernateTemplate.java:420)
    ... 3 more

  • #2
    ?

    Was there a solution?

    Comment

    Working...
    X