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.  [ 4 posts ] 
Author Message
 Post subject: Newbe - SaveOrUpdate
PostPosted: Wed May 09, 2007 4:11 pm 
Beginner
Beginner

Joined: Wed May 02, 2007 12:24 am
Posts: 41
This is a real newbe question.

For some reaons, I can't get the ISession.SaveOrUpdate to work. I can only insert not save.

I have a key and a version.

I've set the key's unsaved-value="any".
I've encapsualte SaveOrUpdate in a trasnaction.
I'm detached persistent objects, so I'm using a different session for saveOrUpdate and Load.

I must be missing something real simple...just can't figure it out.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 4:23 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
SaveOrUpdate calls Save (which is insert) if the object's ID is the same as the unsaved value. It calls Update (which does an update) if the object's ID is not the same.

Since you're setting unsaved-value=any, it will always think it's an insert and not an update.

Can you provide your mapping as well and what you're actually trying to do?

If, for example, your ID is an auto-increment field in the database, then your unsaved-value should be 0. This will tell it to perform an insert when the ID is 0... it will then update the ID. Any subsequent calls to SaveOrUpdate would perform an update.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 5:57 pm 
Beginner
Beginner

Joined: Wed May 02, 2007 12:24 am
Posts: 41
That worked! Thank you. I was really confused :-)

Regards.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 23, 2007 3:58 am 
Newbie

Joined: Thu Jul 05, 2007 4:55 am
Posts: 4
[quote="h1"]That worked! Thank you. I was really confused :-)

Regards.[/quote]

hi...! i'm confused too...can you copy your wirted code in this topic please..?i don't t do a update and i think that my problem is in the mapping file...maybe... :-(


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