Org.hibernate.StaleStateException occurs when you use the Hibernate update operation

Source: Internet
Author: User

Org.hibernate.StaleStateException:Batch Update returned unexpected row count from Update [0]; Actual row count:0; Expected:1

Cause of Error:

Use Hibernate's Saveorupdate method to save the instance. The Saveorupdate method requires an ID of NULL to execute save and, in other cases, to perform the update. When saving the instance is added, but your ID is not NULL, so the update is used, but there is no primary key related value in the database, so an exception occurs.

In the action, Java code:

Public String updatestudent () {

Student s = new Student ();

try {
Beanutils.copyproperties (S, student); Reduce the amount of code by processing the properties of the JavaBean using the reflection mechanism
} catch (Illegalaccessexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
} catch (InvocationTargetException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}

S.setid (ID); Get the ID number of the student you want to update on the page
Studentservice.updatestudent (s);

return Querystudent ();
}

Note: The Beanutils import is org.apache.commons.beanutils.BeanUtils.

Use the links below to view the http://www.cnblogs.com/fayf/archive/2008/08/21/1272982.html

The above represents only personal views, welcome everyone to make bricks (* ^_^ *)

Org.hibernate.StaleStateException occurs when you use the Hibernate update operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.