-->
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: Error while "saveOrUpdate" and IDs
PostPosted: Mon Sep 07, 2009 8:22 am 
Newbie

Joined: Mon Sep 07, 2009 8:07 am
Posts: 2
Hi all together,

I try to build up a little WebStart Client with two databases (local and remote), both with Hibernate Access. Now i try to create a little syncronize mechanism, for this reason i play a little bit around with the different persists-Methods of the hibernate session, and running into errors with the following code snipped:

Code:
   public void saveData(List lst) {
      Session session=sessionFactory.openSession();
      session.getTransaction().begin();
      for (Object e:lst){
         session.saveOrUpdate(e);
      }
      session.getTransaction().commit();
      session.close();
   }


The "lst"-Parameter is a list of changed objects in local database, which should be inserted or updated into the remote database:

Code:
07.09.2009 14:16:15 org.hibernate.jdbc.BatchingBatcher doExecuteBatch
SCHWERWIEGEND: Exception executing batch:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1


my search for this error code bring up the fact, that this error appears if the database can't find the Object which should be edit. But that is for me a little bit strange, in my opinion i use "saveOrUpdate" exactly for this reason: if the object exists -> update, if not -> insert, but that maybe seems a misunderstanding?

Any Ideas?
Thanks for help
Dom


Top
 Profile  
 
 Post subject: Re: Error while "saveOrUpdate" and IDs
PostPosted: Mon Sep 07, 2009 9:59 am 
Newbie

Joined: Mon Sep 07, 2009 8:07 am
Posts: 2
Solution:

I misunderstood the mechism which hibernate use to check if he uses "insert" or "update". I thought hibernate checks the DB if ID-Fields exists or not. But thats seems to be wrong. With my latest tests hibernate just checks if the primary key in the object is set (=update) or nor (=insert).

Greets
D


Top
 Profile  
 
 Post subject: Re: Error while "saveOrUpdate" and IDs
PostPosted: Mon Sep 07, 2009 8:50 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Thanks for the postback! It's great to hear your finding.

Here's a little tutorial on "How Hibernate Works" that may even add more to your understanding of Hibernate and Object Relational Mappings:

http://jpa.ezhibernate.com/Javacode/lea ... rnateworks

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.