-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: StaleStateException problem
PostPosted: Wed May 09, 2007 10:08 pm 
Newbie

Joined: Tue Apr 24, 2007 8:34 pm
Posts: 4
Hi ranchers,

Just want to know that in Hibernate when is this error happens?

Code:
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.checkBatched(Expectations.java:61)
   at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
   at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:24)
   at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2353)
   at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2257)
   at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2557)
   at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   at org.springframework.orm.hibernate3.HibernateTemplate$27.doInHibernate(HibernateTemplate.java:806)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:367)
   at org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:804)



Tried to look at the API, and it says

Code:
/**
* Thrown when a version number or timestamp check failed, indicating that the
* <tt>Session</tt> contained stale data (when using long transactions
* with versioning). Also occurs if we try delete or update a row that does
* not exist.<br>
* <br>
* Note that this exception often indicates that the user failed to specify the
* correct <tt>unsaved-value</tt> strategy for a class!


Did I miss something here? I was just trying to remove a persistent object and then add a new persistent object, wherein, both objects have the same superclass (@MappedSuperClass), there, I have the version field contain in the superclass. Is there anything wrong here?

Any help is appreciated. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 10:16 pm 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
Can you show the code between session open and close?

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 10:48 pm 
Newbie

Joined: Tue Apr 24, 2007 8:34 pm
Posts: 4
Thanks for reply.. I'll be posting my test case...

Code:
public void testAuditEventDelete() throws Exception {
        inProfileDao.save(inboundProfile); //
        flush(); // session.clear() and session.flush()
       
        // get user reference
        User user = userDao.get(1);
        assertNotNull(user);
        assertTrue(user.getId() == 1);
       
        // start audit
        manager.auditEvent(auditMessage, inboundProfile); // it saves the auditMessage then it save a history object for inboundProfile

        inProfileDao.remove(inboundProfile.getId()); // removes the profile

        // check history table
        List<InboundProfileHistory> histories = inProfileHistDao
           .getInboundProfileHistoryByProfileName(profileName); // retrieves the history object
        assertTrue(histories.size() > 0);
        assertEquals(histories.get(0).getName(), profileName);
    }



I'll also post my entity mapping

Code:
@MappedSuperclass
public abstract class AbstractInboundProfile extends BaseObject {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    private Integer version;
}

@Entity
public class InboundProfile extends AbstractInboundProfile {

    // collection objects here
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY,
            mappedBy = "inboundProfile)
    private List<InboundProfileHistory> profileHistories;
}

@Entity
public class InboundProfileHistory extends AbstractInboundProfile {

    private String transactionType;

    @ManyToOne
    private InboundProfile inboundProfile;
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 12:02 am 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
Well the code didn't help as much as I hoped it would. The main thing I was hoping to see was how the session is managed.

It seems like it's managed by Spring?

Does manager.auditEvent() do anything to inboundProfile?

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 1:01 am 
Newbie

Joined: Tue Apr 24, 2007 8:34 pm
Posts: 4
himawan wrote:
Well the code didn't help as much as I hoped it would. The main thing I was hoping to see was how the session is managed.

It seems like it's managed by Spring?


sorry about this, yeah it's managed by Spring,

himawan wrote:
Does manager.auditEvent() do anything to inboundProfile?


Here's the code for auditEvent(), it didn't touch the inboundProfile, it just copy its state to inProfileHistory.

Code:
try {
            auditDao.save(auditMessage);
            if (auditMessage.getTableName() == AuditableData.INBOUND_PROFILE) {
                InboundProfileHistory inProfileHistory = new InboundProfileHistory();
                entity.copyToHistory(inProfileHistory); [b]// copy state[/b]
                inProfileHistory.setInboundProfile((InboundProfile) entity);
                inProfileHistoryDao.save(inProfileHistory);
            }
        } catch (DataAccessException e) {
            throw new AuditException(e.getMessage());
        }


From the source code I post before this, it seems like the hibernate wasn't able to perform autoFlush...(), when it executes the remove() method on the inboundProfile.

I've already tried to put out primary key and the version field from the @MappedSuperClass, instead I put those two fields in the persistent subclasses @Entity, but to no avail, the test case still fails.

Anything more you need to figure this out??


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 1:24 am 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
Ok...so inside your test method,

you are doing a save to inboundProfile.

then you do a flush() which does a session.clear() and session.flush().
session.clear actually cancel pending saves

http://www.hibernate.org/hib_docs/v3/ap ... tml#clear()

So when you try removing inboundProfile later, it finds nothing to remove. Do you need the flush there?

/**
* Thrown when a version number or timestamp check failed, indicating that the
* <tt>Session</tt> contained stale data (when using long transactions
* with versioning). Also occurs if we try delete or update a row that does
* not exist.
<br>
* <br>
* Note that this exception often indicates that the user failed to specify the
* correct <tt>unsaved-value</tt> strategy for a class!

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.