-->
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: using Oracle sequence in composite id
PostPosted: Mon Jan 23, 2006 12:11 pm 
Beginner
Beginner

Joined: Mon Jan 23, 2006 12:01 pm
Posts: 46
Hello,

I'm using Hibernate 3.1. After importing a db schema from Oracle I got, among others, this mapping:

<composite-id name="id" class="hibernate.mypackage.MyTestId">
<key-property name="mainId" type="long">
<column name="MAIN_ID" precision="10" scale="0" />
</key-property>
<key-property name="effectiveDate" type="timestamp">
<column name="EFFECTIVE_DATE" length="7" />
</key-property>
<key-property name="periodType" type="string">
<column name="PERIOD_TYPE" length="20" />
</key-property>
</composite-id>

An additional Java class was created for the composite key (MyTestId). The class created for the actual table was MyTest.
Now one of those columns (MAIN_ID) had a sequence generator created for it (SEQ_MAIN_ID). My question is: is it possible to modify the mapping somehow to tell Hibernate that SEQ_MAIN_ID should be used for creating the MAIN_ID column values?

I'd appreciate any help on the subject.
Thanks,

Marcin Bratek


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 23, 2006 12:21 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
Code:
    <id
        name="intSeqNo"
        type="java.lang.Integer"
        column="int_seq_no"
    >
        <generator class="native">
            <param name="sequence">SEQ_MAIN_ID</param>
        </generator>
    </id>

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 23, 2006 1:18 pm 
Beginner
Beginner

Joined: Mon Jan 23, 2006 12:01 pm
Posts: 46
Does that mean that I can either have a sequence-generated id, or a composite key, but not both? It kind of makes sense, since sequence provides unique values, but still?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 23, 2006 2:49 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
bratek wrote:
Does that mean that I can either have a sequence-generated id, or a composite key, but not both? It kind of makes sense, since sequence provides unique values, but still?


I see no reason for a composite id that includes a generated key. You're welcome to try it, but I think the hibernate developers agree with me as hibernate just seems to work better with surrogate keys. (compared against natural keys)

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


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.