-->
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: overriding sequence generator
PostPosted: Thu Aug 02, 2007 7:45 pm 
Newbie

Joined: Tue Nov 22, 2005 10:08 am
Posts: 17
How to override sequence generator with explicit value?

I use sequence generator

<id name="id" column="person_id">
<generator class="sequence">
<param name="sequence">person_id_sequence</param>
</generator>
</id>

In rare cases I need to set the id value explicitly. If I set the id then during save() hibernate thinks that object is already in db and falls over on trying to update row rather than insert.

What's the easiest way to override the id?

I guess I can just use assigned generator, then if I need to save new object I have to ask a sequence for next value and set it on object straight in my code. But that's not really clean and I have to always remember to grab the next sequence value and set it on object before saving...

Are there any other solutions? Do I have to write new generator?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 06, 2007 4:48 am 
Newbie

Joined: Fri Mar 23, 2007 4:47 am
Posts: 16
Hi

I too am looking for a solution. Have you possibly found one in the mean while?

Martyn


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 09, 2007 12:03 pm 
Newbie

Joined: Thu Aug 09, 2007 11:41 am
Posts: 1
Location: Germany
Take a look at the reference manual chapter

10.9 Replicating object between two different datastores

You might be able to use the same approach for your needs ...

Anyway you would have to make sure that your "manual" generated
ID value and the "automatic" assigned ID's have distinct ranges.

Erwin


Top
 Profile  
 
 Post subject: one solution would be add version
PostPosted: Thu Aug 09, 2007 2:58 pm 
Newbie

Joined: Wed Aug 08, 2007 11:44 pm
Posts: 4
Location: Denver
we had same problem in the past where we were dealing with two different database.


Try to add (or choose one from existing columns) version column to that table.


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.