-->
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.  [ 2 posts ] 
Author Message
 Post subject: update saved object with a new created one
PostPosted: Wed Oct 01, 2003 4:07 pm 
Newbie

Joined: Tue Aug 26, 2003 2:49 pm
Posts: 11
Hi everyone,

I'd like to update an entity existing in the DataBase with a newly created object:

Suppose cat (ID=1234) exist in DB:

Cat cat = new Cat();
cat.setId("1234");
cat.setName("bob");
sess.save(cat);

Hibernate throw an exception because cat already exist.

But what I would like would be that hibernate updates the object.

Any suggestion?

Thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 4:57 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
use
Code:
sess.update(cat);
or
Code:
sess.saveOrUpdate(cat);


What you want is to update an existing object, not save a new one...

Read the 7.5 section of the hibernate reference guide for more informations

[/code]


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