-->
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: Using composite ID, one member from various sequences
PostPosted: Thu May 11, 2006 2:51 pm 
Newbie

Joined: Thu May 11, 2006 2:41 pm
Posts: 3
Location: Manitowoc, WI
Here is the setup:

I have a table with a two field primary key, I'll call the fields FOO and BAR. BAR is an int that is derived from one of 10 possible Oracle sequences. Which sequence is used is determined by the value of FOO.

So if FOO were equal to "001", then we'd call BAR_SEQ_001.nextval. I'm sure you get the picture.

Is there an easy way to model this in hibernate?

Someone in #hibernate suggested that using an Interceptor might work in this situation. From my (very) limited understanding of an Interceptor, would we have the Interceptor look at the value of FOO and make the appropriate sequence call?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 3:18 pm 
Newbie

Joined: Thu May 11, 2006 2:41 pm
Posts: 3
Location: Manitowoc, WI
Someone has told me that I should implement my own key generator class to take in the first parameter and call the appropriate sequence there to set the values for the ID. Has anyone done anything like this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 4:34 pm 
Newbie

Joined: Thu May 11, 2006 2:41 pm
Posts: 3
Location: Manitowoc, WI
From IRC:
Quote:
<max_at_hibernate> yourObject.setValue(new SequenceGenerator().generate((SessionImplementor)session, yourObject))
<max_at_hibernate> in short ;)
<rizzo> is "yourObject" my composite id class?
<rizzo> and where do I specify the sequence name?
<max_at_hibernate> the object is just the object you want an id generated for
<max_at_hibernate> you can use that as "input"
<max_at_hibernate> options are set via seqgen.configure(...)
<max_at_hibernate> look in the source code of sequencegenerator what it uses.


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.