-->
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: Hibernate with Oracle sequence doesn't use it
PostPosted: Wed Aug 24, 2011 3:07 am 
Newbie

Joined: Fri Aug 19, 2011 4:25 am
Posts: 3
I have configured hibernate to use oracle sequence. Sequence is created with cache=20, increment=1.

All works fine, hibernate persisting entities. The id value is strange: 50,51....76,201,202...209,1008,1009,5129,5130 ....

If I ask for sequence value (select hibernate_sequence.nextval from dual) I get value like 2,3,4 ....

If I turn on hibernate sql debug, there is time to time call "select hibernate_sequence.nextval from dual" but number assigned by hibernate to ID doesn't relay on sequence!

Code:
@Id @Column(name = "ID", insertable = false, updatable = false)
@SequenceGenerator(name = "SequenceIdGenerator", sequenceName = "HIBERNATE_SEQUENCE")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SequenceIdGenerator")
private Long id;


Top
 Profile  
 
 Post subject: Re: Hibernate with Oracle sequence doesn't use it
PostPosted: Wed Aug 24, 2011 4:02 am 
Newbie

Joined: Mon Dec 10, 2007 7:03 am
Posts: 14
Add allocationSize=1 to your @SequenceGenerator
Code:
@SequenceGenerator(name = "SequenceIdGenerator", sequenceName = "HIBERNATE_SEQUENCE", allocationSize=1)


The problem stems from a strange default value in JPA allocationSize=50, in fact it's for performance reasons.


Top
 Profile  
 
 Post subject: Re: Hibernate with Oracle sequence doesn't use it
PostPosted: Wed Aug 24, 2011 8:05 am 
Newbie

Joined: Fri Aug 19, 2011 4:25 am
Posts: 3
Thank you, it works.

Explanation is there: http://stackoverflow.com/questions/7171626/hibernate-with-oracle-sequence-doesnt-use-it


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.