-->
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.  [ 2 posts ] 
Author Message
 Post subject: SequenceGenerator and GeneratedValue annotations
PostPosted: Mon Jun 04, 2007 4:06 pm 
Newbie

Joined: Mon Jun 04, 2007 3:38 pm
Posts: 2
Location: Boston, MA
Hello,
We are using Hibernate Core with Hibernate Annotation (with Oracle as database). We are using oracle sequence for primary keys. Everything works great except for one following strange issue that we recently noticed:

The primary key values that get saved in the database are different from the actual oracle sequnce value. Following is the code snippet of our model.

We are using Hibernate version:3.2.0 and the oracle database sequnce name in this case is SEQ_ORD_ID


@Entity
@Table(name = "ORDER")
@SequenceGenerator(name = "SEQ_ORDER", sequenceName = "SEQ_ORD_ID")
public class Order implements Serializable {

private static final long serialVersionUID =4791234021227501647L;

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_ORDER")
@Column(name = "ORD_ID")
private Long orderId;

@Column(name = "ORDER_DATE")
private Date orderDate;

public Long getOrderId() {
return orderId;
}

public void setOrderId(Long orderId) {
this.orderId = orderId;
}


In the hibernate log with SQL tracing enabled we see the "select SEQ_ORD_ID.nextval from dual" only once after the application server is started.

Am I missing anything here ? Any help/insight is to why the primary key value that gets saved is different from actual sequnce value that oracle database holds, is greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 05, 2007 3:16 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hi,

Add the following code to to the @SequenceGenerator annotation:

Code:
allocationSize=1


This should solve the problem.

Cheers,

Andy

_________________
Rules are only there to be broken


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