-->
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: Altering sequences through annotations in postgres
PostPosted: Tue Jan 02, 2007 8:01 am 
Newbie

Joined: Thu Oct 26, 2006 7:16 am
Posts: 5
Hibernate version: 3.2

Name and version of the database you are using: postgres 8.1.4

Hi,

I'm trying to set up a sequence in postgreSQL like this:
Code:
@Id
  @GeneratedValue(generator="entityGen")
  @GenericGenerator(name="entityGen", strategy="sequence",
      parameters= {
        @Parameter(name="min_value", value="100")
      }
  )
  public Integer getId() {
    return id;
  }


The problem is that the min_value stays at 1 in the database table (and do not change to 100). (I've also tried to use @SequenceGenerator and set initialValue to 100, but hibernate does not seem to support the initialValue for @SequenceGenerator..)

Anyone knows how I can changed min_value, or other attributes in the sequence table in Postgres, using annotations?

- Olav


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 02, 2007 9:03 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Did you just run Hibernate or did you run SchemaUpdate? Because Hibernate won't do anything with this I guess. These infos are only present for SchemaUpdate to create the right sequence, so if you don't run SchemaUpdate, or at least force its automatic execution through the "hbm2ddl" property in the hibernate.cfg.xml file, it won't change anything related to the sequence in the db (apart from just calling nextval on it).

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 02, 2007 9:27 am 
Newbie

Joined: Thu Oct 26, 2006 7:16 am
Posts: 5
yes, i updated the schema.

I found out that i can change the minvalue and lastvalue by doing this:

Code:
@Id
  @GeneratedValue(generator="entityGen")
  @GenericGenerator(name="entityGen", strategy="sequence",
      parameters= {
        @Parameter (name="sequence", value="entity_sequence START 100 MINVALUE 100")
      }
  )
  public Integer getId() {
    return id;
  }


but now i get org.hibernate.exception.SQLGrammarException: could not get next sequence value....(?)


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.