-->
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.  [ 10 posts ] 
Author Message
 Post subject: Oracle "Identity" Column
PostPosted: Wed Feb 07, 2007 9:42 pm 
Newbie

Joined: Sun Jan 01, 2006 11:58 pm
Posts: 12
Hi,

Often in Oracle mimic Identity column using a DB Trigger On Insert with a Sequence. Is it possible to use the generator identity in Hibernate or it requires to write your own identifier generator?

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 08, 2007 2:50 am 
Beginner
Beginner

Joined: Mon Nov 22, 2004 11:21 am
Posts: 42
Yes, for sure. Just edit the <id>-tag of your mapping file for the specific table:
Code:
<id name="Id" type="integer" column="PAR_ID" length="9">
   <generator class="sequence">
      <param name="sequence">PAR_SQ</param>
   </generator>
</id>

where: PAR_SQ is the name of sequence.[/code]

_________________
Real programmers confuse Halloween and Christmas because OCT 31 = DEC 25


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 09, 2007 1:42 pm 
Newbie

Joined: Sun Jan 01, 2006 11:58 pm
Posts: 12
gskempes wrote:
Yes, for sure. Just edit the <id>-tag of your mapping file for the specific table:
Code:
<id name="Id" type="integer" column="PAR_ID" length="9">
   <generator class="sequence">
      <param name="sequence">PAR_SQ</param>
   </generator>
</id>

where: PAR_SQ is the name of sequence.[/code]

Thank you for your reply.

I asked if we can use generator name "identity".
Besides I doubt that generator name "sequence" will work at all because in this case we will have two accesses to the same sequence - one from Hibernate, another from trigger on insert which also increases sequence leaving value in Java code less than in DB.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 12, 2007 2:48 am 
Beginner
Beginner

Joined: Mon Nov 22, 2004 11:21 am
Posts: 42
I was assuming you want to replace the trigger functionality. If you don't then use "assigned". However, you have to code the access to the sequence yourself. Afaik there is no hibernate built-in command for retrieving the next value from a sequence.

_________________
Real programmers confuse Halloween and Christmas because OCT 31 = DEC 25


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 15, 2007 2:03 pm 
Newbie

Joined: Sun Jan 01, 2006 11:58 pm
Posts: 12
gskempes wrote:
I was assuming you want to replace the trigger functionality. If you don't then use "assigned". However, you have to code the access to the sequence yourself. Afaik there is no hibernate built-in command for retrieving the next value from a sequence.

If this is the existing DB with such functionality and with another applications relying on it we can not replace this trigger. From the Hibernate point of view it should look as identity column and I hoped that Hibernate accepts this as identity column.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 11, 2007 10:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I am not saying its the right thing to do but ..... If you
customise the Oracle dialect you should be able to get it to happen.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 14, 2007 7:06 pm 
Newbie

Joined: Sun Jan 01, 2006 11:58 pm
Posts: 12
david wrote:
I am not saying its the right thing to do but ..... If you
customise the Oracle dialect you should be able to get it to happen.

Thank you.

Perhaps it is so common for Oracle database applications consider it as feature request?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 14, 2007 8:58 pm 
Newbie

Joined: Wed Mar 14, 2007 8:30 pm
Posts: 1
hi,
if you don't use oracle Identity column using a DB Trigger, you msut define this column as normal int column, then you can create your own identifier generator to write it.

_________________
software reviews


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 12, 2007 4:35 am 
Beginner
Beginner

Joined: Thu Dec 23, 2004 5:24 am
Posts: 40
Location: Luxembourg
vgendler wrote:
Perhaps it is so common for Oracle database applications consider it as feature request?


What about the "select" id generator ? It looks like it's made for such cases.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 13, 2007 8:02 am 
Beginner
Beginner

Joined: Thu Dec 23, 2004 5:24 am
Posts: 40
Location: Luxembourg
And in case you don't have a natural primary key to use with the select id generator, see also this thread: http://forum.hibernate.org/viewtopic.php?t=973262


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