-->
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: GenerationType.AUTO
PostPosted: Fri Dec 01, 2006 4:36 pm 
Newbie

Joined: Wed Oct 13, 2004 10:21 am
Posts: 4
According to the EJB3.0 spec, the @GeneratedValue annotation's 'generator' property defaults to the "Default id generator supplied
by persistence provider."

I'm using strategy=GenerationType.AUTO, and I've read in the forums that for when GenerationType.AUTO is used with Oracle a sequence will be used as the generator. what will the default sequence name be? Is it *table_name*_seq?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 01, 2006 5:33 pm 
Newbie

Joined: Fri Dec 01, 2006 2:12 pm
Posts: 5
I ran across this earlier today, actually. The default sequence name is hibernate_sequence. Not terribly useful, if you ask me. :)

You can specify a sequence name at the class level with:
Code:
@SequenceGenerator(sequenceName = "mySequence", name = "id_gen")


Then, you can reference that generator in your GeneratedValue annotation like:
Code:
@GeneratedValue(strategy = GenerationType.SEQUENCE, name = "id_gen")


Hope that helps!

-- Alec


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 01, 2006 5:36 pm 
Newbie

Joined: Fri Dec 01, 2006 2:12 pm
Posts: 5
Oh, one more thing. For some reason, the default allocationSize attribute on @SequenceGenerator is 50, which causes the numbers being pulled from your sequence to be multiplied by 50. (Can anyone tell me why you'd EVER want to do that?) Just set allocationSize = 1 to get the raw sequence number.

Code:
@SequenceGenerator(name = "id_gen", sequenceName = "mySequence", allocationSize = 1)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 04, 2006 11:42 am 
Newbie

Joined: Wed Oct 13, 2004 10:21 am
Posts: 4
Wow. So by default, All tables' IDs are generated from one sequence? Now that's a unique identifier. Thanks for the help.


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.