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 8397241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:44:14+00:00 2026-06-09T20:44:14+00:00

I’ve been tasked with restarting a sequence for many different serial columns in a

  • 0

I’ve been tasked with restarting a sequence for many different serial columns in a PostgreSQL database. Normally, I would simply use:

ALTER SEQUENCE serial RESTART WITH 105;

However, it seems that Hibernate is being used to handle the database sequences. I really don’t know anything about Hibernate, but my understanding is that hibernate_sequence is a global sequence for all tables. Is that correct?

I’m assuming that I would need to do the following, then:

ALTER SEQUENCE hibernate_sequence RESTART WITH 105;

But I am not sure what the consequence will be. Let’s assume I have Tables A, B, C, and D. Each of those tables has an ID column of type serial. Will the above SQL statement on hibernate_sequence restart the ID column for ALL of the tables?

Thanks!

  • 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-06-09T20:44:16+00:00Added an answer on June 9, 2026 at 8:44 pm

    First, there’s an underling problem here: You’re treating the value of sequences like they mean something. See the end of the answer.

    Now, with Hibernate, it depends on how the user has configured the mappings. A well configured Hibernate instance will use the same sequences everything else does.

    Unfortunately, most mappings aren’t very good – or rather, I think Hibernate’s default behaviour is horrible and should always be overridden. The default sequence used is indeed a shared hibernate_sequence for all tables. However, it’s entirely possible to have some tables using their own sequences, and other tables using the shared hibernate_sequence, or to have all tables properly using their own sequences.

    To enable a definitive answer you’d need to post your mappings.

    If the table(s) you want to change the ID generation of are using the correct sequences for their tables in their Hibernate mappings, you can just go ahead and ALTER SEQUENCE that sequence. If your mappings are via JPA, that’s done with a @SequenceGenerator and @GeneratedValue with GenerationType.SEQUENCE. If it’s done via orm.xml, hbm.xml or the old-style Hibernate annotations you’ll need to check the manual. Or, if Hibernate is the only client that writes to the DB, look at the sequences to see if they’re going up using SELECT * FROM sequence_name.

    If the mappings for the table(s) of interest are using the shared hibernate_sequence you probably can’t do what you want without fixing the Hibernate mappings. You’d need to change the mappings so the mapping for the table(s) of interest use a different sequence, then`LOCK TABLE and set the start point for those sequences to the greatest row currently in the table.

    Sequences: Why do you need to change or restart the sequence? It shouldn’t matter, since a synthetic primary key is just a meaningless number that you compare for equality with other meaningless numbers. What’s the problem you’re trying to solve?

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in

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.