-->
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: ID generation on SQL Server and Oracle
PostPosted: Wed May 17, 2006 5:02 am 
Beginner
Beginner

Joined: Tue Mar 28, 2006 3:44 am
Posts: 22
Hi all

I'm struggling with an issue concerning automatic primary key generation. There is nothing special so far with my primary keys, they're just simple data types. The type is Numeric on a SQL Server and on an Oracle instance. both databases are prepared to autoincrement the primary key.

But... here comes the problem. The excerpt of my XML mapping file shows that I use native for utmost flexibility.
Code:
...
<id name="ItemId" column="ITEM_ID" type="Decimal" unsaved-value="0">
      <generator class="native"/>
</id>
...


On the SQL Server everything is working fine. But when I switch to Oracle this configuration asks the database to recieve the new primary key value from a sequence called hibernate_sequence but of course there is no such sequence because every table has its own one.

To avoid this I can use the following XML configuration for Oracle
Code:
...
<id name="ItemId" column="ITEM_ID" type="Decimal" unsaved-value="0">
      <generator class="sequence">
            <param name="sequence">itm_seq</param>
      </generator>
</id>
...


So far this works fine. Though I wonder if it's possible to use native in the XML mapping file for Oracle too and use the correct sequence for each table. Is something like this possible or do I have to change the XML mapping file when I switch the database?

Thanks in advance,
Chavez


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 8:21 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You can use it like this:
Code:
<id name="ItemId" column="ITEM_ID" type="Decimal" unsaved-value="0">
      <generator class="native">
            <param name="sequence">itm_seq</param>
      </generator>
</id>


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 18, 2006 3:02 am 
Beginner
Beginner

Joined: Tue Mar 28, 2006 3:44 am
Posts: 22
Hi Sergey,

thanks for your help. This solves the problem! :)

Greetings,
Chavez


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.