-->
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.  [ 5 posts ] 
Author Message
 Post subject: Sequence in postgres
PostPosted: Thu Sep 20, 2007 3:37 pm 
Newbie

Joined: Tue Jun 12, 2007 6:44 am
Posts: 13
Location: Brazil
Hi All.

I have a simple Entity whose field id is as follows
@Id @GeneratedValue(strategy=GenerationType.AUTO) Long id;

This works fine. a sequence previously created by hibernate is used to generate a value for id column in database.

if I do this
alter table pessoa alter id set default nextval('seqpessoa');

then change the generation strategy to:
@Id @GeneratedValue(strategy=GenerationType.IDENTITY) Long id;

I get an error message "Unable to get the value for id column after inserting". Strange is that the sequence value is incremented. But no row in database is commited.

Anybody suggests a way to use user-defined sequences with hibernate??


Tnx in advance!!!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 20, 2007 4:02 pm 
Beginner
Beginner

Joined: Tue Aug 14, 2007 6:29 pm
Posts: 27
Location: chicago
What is <generator class= option you are using ?

Test by dropping and re-create the sequence.

Are you using the sequence against data loaded from any other tables?
I mean sometimes your sequence may not in be in sync with data loaded in the table. Or your sequence may find duplicate value for id which exists already in table.

Sun


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 20, 2007 4:21 pm 
Newbie

Joined: Tue Jun 12, 2007 6:44 am
Posts: 13
Location: Brazil
Hi

I have created a sequence by doing the following:
create sequence seqpessoa;

then did the following:
@Id @GeneratedValue(generator="seqpessoa", strategy=GenerationType.SEQUENCE) Long id;

I get an exception:
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.AnnotationException: Unknown Id.generator: seqpessoa


I dropped table so, sequence isnt out of sync with id column!
Strange isnt it??


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 20, 2007 4:29 pm 
Beginner
Beginner

Joined: Tue Aug 14, 2007 6:29 pm
Posts: 27
Location: chicago
Is this a bug?

Check this.
http://jira.jboss.com/jira/browse/EJBTHREE-139


Top
 Profile  
 
 Post subject: Thank you
PostPosted: Thu Sep 20, 2007 4:34 pm 
Newbie

Joined: Tue Jun 12, 2007 6:44 am
Posts: 13
Location: Brazil
Yeahhh.

Bugs


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