-->
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.  [ 6 posts ] 
Author Message
 Post subject: problem with sequence generator
PostPosted: Mon Jul 03, 2006 12:01 pm 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
When I tried to use the following code:

Code:
   // Property accessors
   @SequenceGenerator(name = "generator", sequenceName = "etel.tsupport_supportid_seq")
   @Id
   @GeneratedValue(strategy = SEQUENCE, generator = "generator")
   @Column(name = "supportid", unique = true, nullable = false, insertable = true, updatable = true)
   public Integer getSupportid() {
      return this.supportid;
   }


The sequence for the primary key was at 80,000 and I inserted 113 rows in multiple sessions, and I got the following id's 4,000,001 , 4,000,002 , 4,000,003 , ... , 4,000,113

The sequence in the database isn't updated though... So if I insert a row into the database table by jdbc/sql I get id 80001...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 03, 2006 9:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Should re-direct this question to the user forum.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 06, 2006 8:01 am 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
Remembered something about having to set initialValue from what another forum user said, so I tried that...

It works if I change the code to:
Code:
   // Property accessors
   @SequenceGenerator(name = "generator", initialValue = 0, allocationSize = 0, sequenceName = "etel.tsupport_supportid_seq")
   @Id
   @GeneratedValue(strategy = SEQUENCE, generator = "generator")
   @Column(name = "supportid", unique = true, nullable = false, insertable = true, updatable = true)
   public Integer getSupportid() {
      return this.supportid;
   }


I am using this code to generate the sequences for postgres:

Code:
public class SerialForPostgres
    extends DelegatingReverseEngineeringStrategy {

    public SerialForPostgres(ReverseEngineeringStrategy delegate) {
        super(delegate);
    }

    public Properties getTableIdentifierProperties(TableIdentifier ti) {
        Properties prop = new Properties();
        prop.setProperty("sequence", ti.getName()+"_"+ ti.getName().substring(1)+ "id_seq");
        return prop;
    }
}


But I have no idea how to set the initialValue or allocationSize when using the tools and the above class.

Any help or pointer to some documentation would be really helpful :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 06, 2006 11:46 am 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
Just checked the code from the tools, and it seems the tools doesn't support initialValue nor allocationSize?

It seems the relevant code is in org.hibernate.tool.hbm2x.pojo.EntityPOJOClass in this method:
Code:
   private void buildAnnSequenceGenerator(StringBuffer wholeString, Properties properties) {
      wholeString.append( "@" + importType("javax.persistence.SequenceGenerator") + "(name=\"generator\", sequenceName=\"" )
            .append( properties.getProperty( org.hibernate.id.SequenceGenerator.SEQUENCE, "" ) )
            .append( "\")" );
      //TODO HA does not support initialValue and allocationSize
      wholeString.append( "\n    " );
   }


would something like this work:
Code:
   private void buildAnnSequenceGenerator(StringBuffer wholeString, Properties properties) {
      wholeString.append( "@" + importType("javax.persistence.SequenceGenerator") + "(name=\"generator\", sequenceName=\"" )
            .append( properties.getProperty( org.hibernate.id.SequenceGenerator.SEQUENCE, "" ) )
            .append( "\"
            .append(, initialValue="+properties.getProperty("initialValue", "0")
            .append(, allocationSize="+properties.getProperty("allocationSize", "0")
            .append(")" );
      wholeString.append( "\n    " );
   }


I am using Hibernate CR2, so it might be that the problem has surface because of Hibernate CR2, not the tools?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 2:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the code should figure out the sequence initial and step value from the id generator and put that into the generated code.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 3:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
dooh - and that is exactly what your code does as far as i can see now ;)

put it in jira as a patch and i'll apply it (note: adding/patching a unittest will speed things up ;)

_________________
Max
Don't forget to rate


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