-->
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.  [ 1 post ] 
Author Message
 Post subject: Composite key with sequence number.How to code solution?
PostPosted: Tue Oct 16, 2007 8:36 am 
Newbie

Joined: Tue Oct 16, 2007 7:53 am
Posts: 1
from FAQ:
Q: I have a composite key where one column holds a generated value - how can I get Hibernate to generate and assign the value?

A: We regard this as an extremely strange thing to want to do. If you have a generated surrogate key, why not just make it be the primary key?

However, if you must do this, you can do it by writing a CompositeUserType for the composite identifier class, and then defining a custom IdentifierGenerator that populates the generated value into the composite key class.


I'd need some information regarding the solution. How do we write and define a CompositeUserType and associate the IdentifierGenerator they are talking about?

Here is the composite key I have to handle (see below). They are both generated by Sequence numbers. We never update a user row because the client whants to keep every revision or every users. Instead we keep a sequence (1+) for every userId (1+).

Code:
<composite-id name="id" class="gouv.ssss.rsipa.modele.entity.Rsipa04t02UsagrId" >
            <key-property name="idUsagr" type="big_decimal">
                <column name="ID_USAGR" precision="22" scale="0" />
            </key-property>
            <key-property name="noSeqncUsagr" type="big_decimal" >
                <column name="NO_SEQNC_USAGR" precision="22" scale="0" />
            </key-property>

        </composite-id>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.