-->
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.  [ 8 posts ] 
Author Message
 Post subject: primary key generation
PostPosted: Fri May 05, 2006 4:38 am 
Newbie

Joined: Tue Oct 04, 2005 1:35 am
Posts: 12
Hibernate version: 3.1

Name and version of the database you are using: Oracle 9

Hi all,
My web application uses Mysql and runs fine.. but now i have to migrate it to oracle for some reason. for every table i have used <generator class="native"/> for Primary Key generation..
in mysql i have used auto-increment feature so i dont hv to worry about PK generation.. but for oracle , what should be my approach so that there are minimum changes done to the code ?

My goal is to make this application portable for any DB.. Specially, MySQL, Oracle and SQL server..

Please help me..

Thanks in advance,

Venkatesh


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 05, 2006 5:37 am 
Newbie

Joined: Thu May 04, 2006 4:04 am
Posts: 5
use this way

<hibernate-mapping>
<class name="....." table="TABLEXXX" schema="TEST_SCHEMA">
<id name="id" type="int">
<column name="ID" precision="22" scale="0" />
<generator class="sequence">
<param name="sequence">TABLEXXX_SEQ</param>
</generator>
</id>
..............
.....

greetings willi


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 05, 2006 6:53 am 
Newbie

Joined: Tue Oct 04, 2005 1:35 am
Posts: 12
Hi icoserve,
Thanks for reply..
but MySQL does not support sequence.. is there no other way, so that application will support Oracle, MYSQL or SQL server at the same time?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 05, 2006 7:14 am 
Beginner
Beginner

Joined: Fri Apr 28, 2006 7:48 am
Posts: 20
Hi,
May be you can try this.

<generator class="increment" />

OR

you can also try this

<generator class="hilo">
<param name="table">hibernate_unique_key</param>
<param name="column"> next_value</param>
<param name="max_lo">100</param>
</generator>

and create a table

CREATE TABLE HIBERNATE_UNIQUE_KEY
(
NEXT_VALUE INTEGER
)


Hope this helps!!!

PS: Please rate the posting if it proves to be useful


Last edited by falgunipm on Mon May 08, 2006 7:49 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 1:46 am 
Newbie

Joined: Tue Oct 04, 2005 1:35 am
Posts: 12
Thanx a lot falgunipm,
Using "hilo" solved my problem..


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 12, 2006 4:16 pm 
Newbie

Joined: Mon Jun 06, 2005 8:53 am
Posts: 16
Hi,

If I have more than one table that need to use the hilo generation, I have to create a new 'hibernate_unique_key' table for each one of them?

Can I have an extra column with an identifier for each table?

Is that possible?

Thanks,
Cristiane


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 13, 2006 2:11 am 
Beginner
Beginner

Joined: Fri Apr 28, 2006 7:48 am
Posts: 20
Hi,
Something like this is valid

CREATE TABLE HIBERNATE_UNIQUE_KEY
(
NEXT_VALUE INTEGER,
COL2 INTEGER
)

File1.hbm.xml
<id name="pk" type="int" unsaved-value="0" column="pk">
<generator class="hilo">
<param name="table">hibernate_unique_key</param>
<param name="column"> next_value</param>
<param name="max_lo">100</param>
</generator>
</id>

File2.hbm.xml
<id name="pk" type="int" unsaved-value="0" column="pk">
<generator class="hilo">
<param name="table">hibernate_unique_key</param>
<param name="column"> COL2</param>
<param name="max_lo">100</param>
</generator>
</id>

In short, you do not have to create separate tables. You can just create a single table having multiple columns which would be primary keys for different tables.

Regards,
falgunipm


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 17, 2006 8:00 am 
Newbie

Joined: Mon Jun 06, 2005 8:53 am
Posts: 16
Hi,

Thanks for the answer, but I'm afraid I cannot use it. Actually I have an existing table for id generation with the following columns:

IdTyp
NextNum
EndNum

In that way each table has it's own record. In your suggestion I will have only 1 record with multiple columns.

Can I extend the hilo generator class to adapt to my table structure?


Thanks,
Cristiane


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.