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

  • Home
  • SEARCH
  • 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 3630910
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:19:47+00:00 2026-05-19T00:19:47+00:00

I have an entity defined with a sequence-generated primary key: @Id @GeneratedValue(strategy = GenerationType.SEQUENCE,

  • 0

I have an entity defined with a sequence-generated primary key:

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_key_gen")
@SequenceGenerator(name = "id_key_gen", sequenceName = "id_key_seq")
@Column(name = "id", unique = true, nullable = false)
public int getId() {
    return this.id;
}

I’m using PostgreSQL, and this key is defined as a serial. According to PostgreSQL

select last_value from id_key_seq;

returns

1603.

When I do a create() to persist an instance of this entity, I’m seeing the following in my logs (unrelated stuff edited out):


05 15:15:26.948 org.hibernate.id.enhanced.SequenceStructure [DEBUG] – Sequence value obtained: 1604

05 15:15:26.948 org.hibernate.event.def.AbstractSaveEventListener [DEBUG] – generated identifier: 1554, using strategy: org.hibernate.id.enhanced.SequenceStyleGenerator


Subsequent SQL insert statements refer to the value 1554, not what it should be using, 1604 (based on the value returned from the SequenceStructure. Where did Hibernate get 1554 from?

Seems to me Hibernate has a bug here – SequenceStructure knows the correct next value, but it isn’t being used. Any idea how to resolve this?

FYI: I’m aware of this page, which says to use GenerationType.AUTO because the “Hibernate folks completely messed this up”, but there isn’t much beyond that not-very-helpful statement.

  • 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-19T00:19:48+00:00Added an answer on May 19, 2026 at 12:19 am

    Looks like if you use GenerationType.SEQUENCE, you need to be specifying an “increment value” of 1 to avoid it using the sequence as a Hi/Lo seed.

    The first answer (the useful one) to the question you posted explains that you need to specify “allocationSize=1” in the @GeneratedValue annotation.

    On newer Hibernate releases you can instead set hibernate.id.new_generator_mappings=true in your Hibernate properties; see the docs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an entity which has an ID field: @Id @Column(name = `U##ID_VOIE`) @GeneratedValue(generator
I defined a generator for a JPA class: <sequence-generator name=MY_SEQ allocation-size=-1 sequence-name=MY_SEQ initial-value=100000000 />
I have the following entity class (in Groovy): import javax.persistence.Entity import javax.persistence.Id import javax.persistence.GeneratedValue
Suppose I have an entity object defined as public partial class Article { public
I am using CoreData and have an Entity ContactList defined, which I created using
I have an Entity (Article) with an Class defined at xcdatamodel. In this class
I'm using core data and I have an entity defined called LogRecord. Elsewhere this
I have an entity which has property Person person(user defined object) so I wanted
I have two entity sets with entities of the same name with properties of
I have defined this Entity class, but it does not seem to save the

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.