-->
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: Howto specify sequence used by GenerationType.SEQUENCE?
PostPosted: Thu Aug 05, 2010 3:35 pm 
Beginner
Beginner

Joined: Tue Jul 03, 2007 8:47 am
Posts: 46
Hi,

Is there a way to specify the seuence used by the sequence-based ID generator?
For now it seems the generator always uses "hibernate_sequence", however it would be great if I could specify each time which sequence to use.

Something like:
Code:
    @GeneratedValue(strategy = GenerationType.SEQUENCE, sequenceName="startkladde_id_seq)
    public Integer id;


Is this possible at all, and if so, only via XML or also via Annotations?

Furthermore, if I insert into "startkladde" the id-values start with 10, although "hibernate_sequence" says the current value is 1.
Any idea why?

Thank you in advance, Clemens


Top
 Profile  
 
 Post subject: Re: Howto specify sequence used by GenerationType.SEQUENCE?
PostPosted: Thu Aug 05, 2010 3:38 pm 
Newbie

Joined: Thu Aug 05, 2010 3:20 pm
Posts: 6
Annotate your class with

Code:
@SequenceGenerator(name="seq_gen", sequenceName="name_of_your_seq", allocationSize=1)


Annotate your column with

Code:
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="seq_gen")



Seems weird to need two annotations, but it works.


Top
 Profile  
 
 Post subject: Re: Howto specify sequence used by GenerationType.SEQUENCE?
PostPosted: Thu Aug 05, 2010 3:56 pm 
Beginner
Beginner

Joined: Tue Jul 03, 2007 8:47 am
Posts: 46
Thanks a lot, that does the job :)

Quote:
Seems weird to need two annotations, but it works.

Well, also fighting a bit with postgres' SERIAL type (and not having this type in the join column) I have aprox. 3 lines of annotation per field definition ;)

I am really glad to have this solved. Thanks a lot!

- Clemens


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.