Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6217921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:30:36+00:00 2026-05-24T07:30:36+00:00

I am using hbm2ddl in my hibernate based application to generate the db schema.

  • 0

I am using hbm2ddl in my hibernate based application to generate the db schema. The value of hibernate.hbm2ddl.auto property is create-drop.

I am using @Entity annotations for my POJO classes.

@Entity 
public class testTable1 {
     @Id     
     @GeneratedValue(strategy = GenerationType.SEQUENCE)
     Long id; 
}

@Entity 
public class testTable2 {
     @Id     
     @GeneratedValue(strategy = GenerationType.SEQUENCE)
     Long id; 
}

However on executing the code I keep getting continuously incremental Id values. e.g. for 2 tables the Id (i.e. Prim Key) should start each with 1. But after inserting records in Table 1, the sequence goes from next value for Table 2. It should start again from 1 for table 2.
I tried GenerationType.SEQUENCE & GenerationType.AUTO. nothing works 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:30:37+00:00Added an answer on May 24, 2026 at 7:30 am

    You are using the Global sequence generator that hibernate provide by default when no generator is provided as specifed by the JPA Spec. To have a private generator you should declare a private generator with the annotation @SequenceGenerator and set the generator attribute of the @GeneratedValue annotation

    Extracted from javadoc

    @GeneratedValue
    (Optional) The name of the primary key generator to use as specified
    in the SequenceGenerator or TableGenerator annotation.

    Defaults to the id generator supplied by persistence provider.

    SequenceGenerator
    This annotation defines a primary key generator that may be referenced by name when a
    generator element is specified for the GeneratedValue annotation. A
    sequence generator may be specified on the entity class or on the
    primary key field or property. The scope of the generator name is
    global to the persistence unit (across all generator types).

    Example:

    @SequenceGenerator(name="EMP_SEQ", sequenceName="private_sequence")

    Hibernate recommends that new projects use hibernate.id.new_generator_mappings=true as the new generators are more efficient and closer to the JPA 2 specification semantic

    Section 1.3. Properties
    2.2.3. Mapping identifier properties

    Complete example

    @Entity
    @SequenceGenerator(name="PRIVATE_SEQ", sequenceName="private_sequence")
    public class test {
    
        @Id
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="PRIVATE_SEQ")
        Long id;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Env: JPA 1, Hibernate 3.3.x, MySQL 5.x We auto generate database schema using hbm2ddl
I'm using hibernate with hbm2ddl.auto=update so that it'll automatically generate my oracle tables for
I have parametrized persistence.xml. I am trying to generate ddl schema using hbm2ddl. How
I'm using Hibernate (JPA2) hibernate.hbm2ddl.auto=update for test and hibernate.hbm2ddl.auto=validate for production. What I want
I write an application based on an already existing database (postgreSQL) using JPA and
I'm using Hibernate 3.5.2-FINAL with annotations to specify my persistence mappings. I'm struggling with
I am interested in how hibernate.hbm2ddl.auto=validate actually works and I am struggling to find
I am using hbm2ddl to autocreate the schema by including this line in configuration:
After reading Hibernate: hbm2ddl.auto=update in production? some questions arose. First of all, the reason
I'm trying to configure a Spring+Hibernate web application using JNDI instead of a properties

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.