-->
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: composite-id auto-generation
PostPosted: Thu Sep 11, 2008 1:57 am 
Newbie

Joined: Thu Sep 11, 2008 1:05 am
Posts: 1
HibernateMapping:

<composite-id name="id" class="TbPatientId">
<key-property name="researchId" type="int">
<column name="research_id" />
</key-property>

<key-property name="centerId" type="int">
<column name="center_id" />
</key-property>

<key-property name="patientId" type="int">
<column name="patient_id" />
</key-property>
</composite-id>

DB Rows:
research_id | center_id | patient_id
1 | 1 | 1
1 | 1 | 2
1 | 2 | 1
1 | 2 | 2
1 | 2 | 3

Problem:

newbie question: To insert a new patient for a specific research_id and center_id, how can I auto-increment the patient_id using Hibernate? For example: to insert a new patient for research_id=1 and center_id=2, I need to automatically increment patient_id to 4, how to do that with hibernate <generator> or something else similar?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2008 6:37 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Yes, create a class implementing the Hibernate generator, to which you can pass parameters indicating how you would icrement.

It is detailed here
http://www.hibernate.org/hib_docs/refer ... pping.html
(section 5.1.4.1. Generator)

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 29, 2008 2:24 am 
Newbie

Joined: Mon May 19, 2008 12:42 am
Posts: 10
Hi,

Can you please elaborate on how the <generator> will be used for composite PK?. In my situation (see hbm below) XYZ_REQUEST_ID needs to be auto-generated from xyz.sequence_application_id sequence, and XYZ_REQUEST_SITE_ID is supplied by the application.



Code:
    <class name="com.xyz.entity.Request"
        table="XYZ_REQUEST" schema="XYZ">
        <composite-id>
       
              <key-property name="rqSiteId"
                  type="java.lang.String">
                  <column name="XYZ_REQUEST_SITE_ID" length="1" not-null="true" />
              </key-property>
              <key-property name="rqId" type="java.lang.Integer">
                  <column name="XYZ_REQUEST_ID"  />
              </key-property>

            <generator class="org.hibernate.id.enhanced.SequenceStyleGenerator">
            <param name="sequence_name">xyz.sequence_application_id</param>
            <param name="initial_value">1</param>
            <param name="increment_size">1</param>
            </generator>               
        </composite-id>   


The exception says :
Code:
org.hibernate.id.IdentifierGenerationException: this id generator generates long, integer, short
   at org.hibernate.id.IdentifierGeneratorFactory.createNumber(IdentifierGeneratorFactory.java:167)
   at


How do we specify that only for one of the key-property we need to use the generator?


Top
 Profile  
 
 Post subject: Re: composite-id auto-generation
PostPosted: Thu Mar 01, 2012 8:48 am 
Newbie

Joined: Thu Mar 01, 2012 7:24 am
Posts: 1
I have exactly the same problem, is there any solution ?

Thanks for advice.


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.