I'm facing this problem for a days.
Quote:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
This exception has happened in many entities, but it happens only sometimes.e.g: The user saves 5~10 customers it's working, in the 11° happens this exception.In the 12° it's working again.
I put some code to help me to find the source of this exception:
Code:
try {
//save the customer
this.session = HibernateUtil.openSession(id);
this.tx = this.session.beginTransaction();
this.session.saveOrUpdate(customer);
this.session.flush();
tx.commit();
return customer;
} catch ( Exception e ) {
System.out.println("Customer: " + customer );
if( customer != null )
System.out.println("Customer code: " + customer.getCode() );
}
When the exception happen it writes in the log ( the error occurs in production, I can't simulate it ):
Quote:
Customer code: 576
I use the Hibernate Envers to audit the database, so every register needs to be registered in it.But this customer code 576 isn't in the database.
Question:
If the customer code is annotated to be auto-increment.This will only be created when this register save in the database.How the code was created if the customer was not saved?Code:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(columnDefinition="SMALLINT(4) UNSIGNED ZEROFILL")
private int code;
Can anyone help me?