-->
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.  [ 7 posts ] 
Author Message
 Post subject: Hibernate Exception on update
PostPosted: Tue Jul 17, 2007 1:01 am 
Newbie

Joined: Mon Jun 11, 2007 2:48 am
Posts: 10
Hi,

I'm getting a hibernate exception when i try to update only 2 fields (which are composite primary key) of the table.... when i try to update any other field i don't get an exception.

The exception i get is:


org.hibernate.HibernateException: Unexpected row count: 0 expected: 1
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:32)
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:1982)
at org.hibernate.persister.entity.BasicEntityPersister.updateOrInsert(BasicEntityPersister.java:1909)
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:2149)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 17, 2007 2:03 am 
Newbie

Joined: Fri Jun 29, 2007 9:03 am
Posts: 12
Hi,

Can you pls paste the line(s) of code you are using .. also paste the HQL queries which are generated while updating the records ..for both cases i.e when u update the composite key values and when u update the other fields of table.

Thanks !!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 17, 2007 2:07 am 
Beginner
Beginner

Joined: Tue May 08, 2007 8:26 am
Posts: 21
I once asked a similar question, the problem is that when you change the primary key value of an object, hibernate does not know what record he has to update since the primary key value changed (which is the identifier for the record)
The solution is to first delete the old object, then insert the new one

If anyone has a better solution I too would like to know it


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 17, 2007 2:10 am 
Newbie

Joined: Mon Jun 11, 2007 2:48 am
Posts: 10
When i update other fields the query which gets generated is . Here i don't get any exception:

update HSATESTUSER.VALID_BISYS_PAYER_PLAN set STANDARD_IND=?, BISYS_PLAN_DECSRIPTION_TXT=? where PAYER_PARTY_ID=? and BISYS_BRANCH_ID=? and BISYS_PLAN_ID=?


But when i update either BISYS_BRANCH_ID=? or BISYS_PLAN_ID=? then an exception is thrown with the same query generated:


update HSATESTUSER.VALID_BISYS_PAYER_PLAN set STANDARD_IND=?, BISYS_PLAN_DECSRIPTION_TXT=? where PAYER_PARTY_ID=? and BISYS_BRANCH_ID=? and BISYS_PLAN_ID=?


Exception thrown is:

org.hibernate.HibernateException: Unexpected row count: 0 expected: 1
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:32)
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:1982)
at org.hibernate.persister.entity.BasicEntityPersister.updateOrInsert(BasicEntityPersister.java:1909)
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:2149)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:75)


Code used is:

I'm here setting the value to my Valid Bisys Payer Plan hibernate bean from the TO:

argValidBisysPayerPlan.setStandardInd(IHSACommonConstants.INDICATOR_Y);
validBisysPayerPlanPK.setBisysBranchId(argPayerDetailsTO.getBranchId());
validBisysPayerPlanPK.setBisysPlanId(argPayerDetailsTO.getPlanId());
validBisysPayerPlanPK.setPayerPartyId(argPayerObligor.getPayerPartyId());
argValidBisysPayerPlan.setComp_id(validBisysPayerPlanPK);
argValidBisysPayerPlan.setBisysPlanDecsriptionTxt(argPayerObligor.getPayerPartyNm());
}



//update the valid bisys payer plan table
this.getHibernateTemplate().update(validBisysPayerPlan);


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 17, 2007 2:26 am 
Newbie

Joined: Mon Jun 11, 2007 2:48 am
Posts: 10
But even if i try to delete the hibernate object first and then try to save it it gives me the same exception while deleting itself.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 20, 2007 1:59 am 
Beginner
Beginner

Joined: Tue May 08, 2007 8:26 am
Posts: 21
try to print the id fields of the object you are trying to delete/edit, they must be a combination of id's that is not present in the db


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 20, 2007 2:39 am 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
Two things:
1.) As radic already stated: you can't update id-Fields, because for hibernate new id means a new object. So you have to do the delete-insert
2.) you can't insert a new object using update(). when you have deleted the old row and changed the id-value you have to use save() to store the object to the database. come to think of it: the object may hav to be in detached state to do these things....


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