-->
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: Force Hibernate to save a new instance of a queried object
PostPosted: Sun Jan 23, 2005 7:44 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Hi all,

I'm using hibernate 2.1.6. I use it with PosgreSQL with the version
7.4.1.jdbc3
of the jdbc driver.

I'm asking myself about the right method to use to save a new instance of an object already existing in the database.

For instance :

(myObject has got an id and a name property, and the necessary getters and setters, the id is a generated="sequence" one.).

Session s = ...;
s.save(myObject);

Here, I commit.

Then, I get the object and try to save it as a new one. (i.e. as a new line in the db). The only way I've found to do it is to modify the id, setting it at 0 and calling saveOrUpdateCopy().

Is this the normal way or is there a better way to do it ?

In fact, I'd like to be able to do it because I'm versioning my objects.

I just want to save a new line with sometime only one field modified of the quieried instance. But if I use hibernate with the common save, it only calls update, which I absolutely don't want.

Could you help me ?

thanks a lot.


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.