-->
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.  [ 3 posts ] 
Author Message
 Post subject: Request for solution of my Exception
PostPosted: Mon Jan 10, 2011 7:29 am 
Newbie

Joined: Mon Jan 10, 2011 7:23 am
Posts: 1
Hi ,
i am suman.

i have a problem with hibernate...when i am executing the getHibernateTemplate().update(object); the following error coming.

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


the scenario of exception coming is:
1)i have a page in that page had one bulk field check box,when i am check that bulk check box i added the deal with four child records with parent record id.
2)second in that page i uncheck the bulk deal then immediatly i want to delete the child records from my database so that i wrote that code it was successfully deleted child records from the database.
3)now again i am check that bulk check box and i am adding four child records and updating the deal.......when the compilation comes to the
getHibernateTemplate().update(object);

the following error coming:
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

the methods i wrote for the deletion of child records...........as follows:

DaoImpl class:
public GroupDeal removeDealSlabs(GroupDeal groupDeal)throws Exception{
if(groupDeal!=null){
groupDeal= (GroupDeal) getHibernateTemplate().get(GroupDeal.class, groupDeal.getGroupDealId());
GroupDealSlabs c = null;
while( groupDeal.getGroupDealSlabses().iterator().hasNext()){
c = (GroupDealSlabs) groupDeal.getGroupDealSlabses().iterator().next();
getHibernateTemplate().delete(c);
groupDeal.getGroupDealSlabses().remove(c);
}
groupDeal.getGroupDealSlabses().clear();
getHibernateTemplate().evict(c);
getHibernateTemplate().evict(groupDeal);
getHibernateTemplate().flush();
}
return groupDeal;
}


public boolean updateGroupDeal(final GroupDeal groupDeal) throws Exception{
boolean result = false;
if (getHibernateTemplate() != null) {
getHibernateTemplate().update(groupDeal); Here i am getting the exception as the scenario above i mentioned the third step
getHibernateTemplate().flush();
result = true;
}
return result;
}

hbm file content:
<set name="groupDealSlabses" inverse="true" lazy="false" order-by="Group_Deal_Slab_Price" cascade="all-delete-orphan">
<key>
<column name="Group_Deal_ID" not-null="true" />
</key>

<one-to-many class="com.yatra.groupdeals.dao.model.GroupDealSlabs" />
</set>

These my problem sir.....i need some help from you,i have seen so many sites for avoid these exception but i didnt get a solution for that......


Top
 Profile  
 
 Post subject: Re: Request for solution of my Exception
PostPosted: Mon Jan 10, 2011 6:25 pm 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
Shouldn't this be inside the remove cycle?

getHibernateTemplate().evict(c);


Also, you are using iterator in very strange way.

while( groupDeal.getGroupDealSlabses().iterator().hasNext()){
c = (GroupDealSlabs) groupDeal.getGroupDealSlabses().iterator().next();
getHibernateTemplate().delete(c);
groupDeal.getGroupDealSlabses().remove(c);
}

Should be this, but your way also works:
Iterator it = groupDeal.getGroupDealSlabses().iterator().
while( it.hasNext()){
c = (GroupDealSlabs) it.next();
getHibernateTemplate().delete(c);
groupDeal.getGroupDealSlabses().remove(c);
//-->this missing?
getHibernateTemplate().evict(c);
}


Top
 Profile  
 
 Post subject: Re: Request for solution of my Exception
PostPosted: Mon Jan 10, 2011 6:27 pm 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
Aa sorry, I see, you cannot reuse the iterrator because of modifications, maybe. Ok.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.