-->
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: quesiton on key generation...
PostPosted: Mon Oct 20, 2003 3:13 pm 
Beginner
Beginner

Joined: Fri Sep 05, 2003 10:17 am
Posts: 42
I have the need to save the primary key that is generated from my oracle sequence into another column in my database beside my promary key column. My mapping document specified the primary key attribute be generated from my sequence but i also want to store this value in another field. Any suggestions on saving the sequence-generated primary key in a filed other than the id field is much appreciated.
thanks in advance for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 20, 2003 3:36 pm 
Newbie

Joined: Mon Oct 20, 2003 3:03 pm
Posts: 13
The id should be available after a sess.save(), where sess is the hibernate session.

In my code here (where scenario uses a hilo generator), I see the id printed in the next line.

Scenario scenario = new Scenario("foo");
sess.save(scenario);
cat.debug("saved scenario= "+scenario);

You could then update the object.

BTW, why do you want to do this?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 20, 2003 3:43 pm 
Beginner
Beginner

Joined: Fri Sep 05, 2003 10:17 am
Posts: 42
it is an interresting problem, i knew this is one way to get the ID i also lnow of the LifeCycle interface but wanted to see if there was yet another way of doing this, perhaps right in the mapping document.

the reason we are doing this it to provide 'code' which for now will be the primary key for the attribute. at some point later in the lifecycle of this app the code may be something different that the primary key. so for now, we want to use the PK to identify the data as this is going to be unique and is 'right there' on the insert. i hope this makes sense.

we still have a PK attribute but also have a code attribute, which for now will be the PK. yes i know there is some data redundancy but this is by design.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 20, 2003 5:38 pm 
Newbie

Joined: Mon Oct 20, 2003 3:03 pm
Posts: 13
>it is an interresting problem, i knew this is one way to get the ID

figured my solution was too obvious

> i also lnow of the LifeCycle interface but wanted to see if there was yet
> another way of doing this, perhaps right in the mapping document.

With Lifecycle interface I wonder if you won't make the object "dirty" again and require an update.

> the reason we are doing this it to provide 'code' which for now will be the
>primary key for the attribute. at some point later in the lifecycle of this app >the code may be something different that the primary key. so for now, we
>want to use the PK to identify the data as this is going to be unique and is
>'right there' on the insert. i hope this makes sense.

Makes sense. Still don't know a good way to do it. How about a "trigger" or a script that runs occasionally and updates all null " data redundancy" fields with the PK (since this is a temporary solution)?


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.