-->
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: Forcing save even if primary key not null
PostPosted: Fri Aug 31, 2007 5:16 am 
Beginner
Beginner

Joined: Wed Apr 13, 2005 12:49 pm
Posts: 34
Hey folks,

We have a mapping that has a sequenceGenerator for creating the primary key. Alas as part of some new business we now need to be able
provide a primary key or not to the object. Alas when we provide a primary key hibernate thinks that the object has already been saved and doesn't
attempt to persist the object. Is there anyway we can override the behaviour that if the primary key is not null then hibernate doesn't save it
automatically?

thanks,
Mark.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 31, 2007 8:53 am 
Regular
Regular

Joined: Thu Oct 19, 2006 12:07 pm
Posts: 75
Hi!

Did you try this:
Code:
<id unsaved-value="any" ... >

or
Code:
<id unsaved-value="undefined" ... >

?

You can also look into Interceptor.isUnsaved()

Regards,
David


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 31, 2007 9:22 am 
Beginner
Beginner

Joined: Wed Apr 13, 2005 12:49 pm
Posts: 34
Hey Xerces*,

Thanks for the reply.
yeah I'm looking at it now. I'm using the <version> tag and have added a column to my table.

I was worried that unsaved-value="any" would mean that the object would always be regarded as new?

unsaved-value="undefined" kinda implies to me that it will only attempt the save when the id is null. My object can have a null id and also have them assigned within the process without retrieving the value from the database, so the latter objects won't be saved.

What do ye think?

thanks,
Mark.


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.