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: Ignoring generated value
PostPosted: Mon Feb 11, 2008 3:07 pm 
Newbie

Joined: Mon Feb 11, 2008 3:00 pm
Posts: 2
On my entities I have the id generated using the uuid generator:
@Id @GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid",strategy="uuid")

This allows me to have id's guaranteed to be unique across environments (dev/stage/prod). However, I also want the ability to move my data across environments and still maintaining id's.

The problem I have is that if I migrate an object which has the id set and use the session.save(), then hibernate insists on using the generator, eventhough my primary key has a perfectly valid value.

Is there any way to turn of this behaviour?

Thanks in advance

_________________
Best regards


Lars Hansen


Top
 Profile  
 
 Post subject: Re: Ignoring generated value
PostPosted: Mon Feb 11, 2008 8:29 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
I am wondering if you could extend this class, modify id annotation to assigned and in those scenarios use the extending class. I am not really sure if this works.


Farzad-


Top
 Profile  
 
 Post subject: Re: Ignoring generated value
PostPosted: Tue Feb 12, 2008 3:22 am 
Newbie

Joined: Mon Feb 11, 2008 3:00 pm
Posts: 2
farzad wrote:
I am wondering if you could extend this class, modify id annotation to assigned and in those scenarios use the extending class. I am not really sure if this works.


Farzad-

Thanks for the input. Perhaps its possible, but that will require me having two classes for each of my hibernated classes, which will quite bothersome in the long run.

Another hack I thought of was to have a helper class that used simple JDBC to create a row with the new id and then updating that id through Hibernate, but again, definately not a preferred approach if Hibernate could help in some way.

I was hoping there were some options one could put on the generator.

_________________
Best regards


Lars Hansen


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.