-->
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.  [ 1 post ] 
Author Message
 Post subject: Question about auto-increment Hibernate
PostPosted: Sun May 30, 2010 8:17 pm 
Newbie

Joined: Sat Mar 06, 2010 1:19 pm
Posts: 8
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?


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

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.