-->
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: Force insert on update
PostPosted: Wed Feb 03, 2010 11:23 am 
Newbie

Joined: Wed Feb 03, 2010 11:11 am
Posts: 2
Is it possible to force inserting a new record instead of updating an existing record?

I've a class "User" with a many-to-one relation to the "Contract" class. When the contract of a user is changed, a new contract record should be inserted in the contracts table instead of updating the existing one.
Code:
<many-to-one class="Contract" name="Contract" column="ContractId" cascade="save-update" />


Top
 Profile  
 
 Post subject: Re: Force insert on update
PostPosted: Fri Feb 05, 2010 5:11 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
- You can try an "instead of" trigger delegating this functionality to the database
- build the logic in your business layer.
- checkout the hibernate event model. Somewhere in a before update phase you probably can change the object to a new instance

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Force insert on update
PostPosted: Tue Feb 09, 2010 6:23 am 
Newbie

Joined: Wed Feb 03, 2010 11:11 am
Posts: 2
Probably building this in the business layer is the best method for us to implement this behavior.


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.