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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:41:06+00:00 2026-05-18T21:41:06+00:00

Is there a way to specify distinct sequences for each table in Hibernate, if

  • 0

Is there a way to specify distinct sequences for each table in Hibernate, if the ID is defined on a mapped superclass?

All entities in our application extend a superclass called DataObject like this:

@MappedSuperclass
public abstract class DataObject implements Serializable {
    @Id 
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name = "id")
    private int id;
}

@Entity
@Table(name = "entity_a")
public class EntityA extends DataObject { ... }

@Entity
@Table(name = "entity_b")
public class EntityB extends DataObject { ... }

This causes all entities to use a shared sequence, the default hibernate_sequence.

What I would like to do is use a separate sequence for each entity, for example entity_a_sequence and entity_b_sequence in the example above. If the ID were specified on the subclasses then I could use the @SequenceGenerator annotation to specify a sequence for each entity, but in this case the ID is on the superclass. Given that ID is in the superclass, is there a way I can use a separate sequence for each entity — and if so, how?

(We are using PostgreSQL 8.3, in case that’s relevant)

  • 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-18T21:41:07+00:00Added an answer on May 18, 2026 at 9:41 pm

    Have you tried doing it this way ?

    @MappedSuperclass
    public abstract class DataObject implements Serializable {
        @Id 
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "idgen")
        @Column(name = "id")
        private int id;
    }
    
    @Entity
    @SequenceGenerator(initialValue = 1, name = "idgen", sequenceName = "entityaseq")
    @Table(name = "entity_a")
    public class EntityA extends DataObject { 
    
    }
    
    @Entity
    @SequenceGenerator(initialValue = 1, name = "idgen", sequenceName = "entitybseq")
    @Table(name = "entity_b")
    public class EntityB extends DataObject {
    
    }
    

    I’m sorry I don’t have the required environment to test it right now but I’ll try it later.

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

Sidebar

Related Questions

Is there a way to specify, for example 4 distinct values for a varchar
Is there a way to specify a child's initial window position in Qt? I
Is there a way to specify a one dimensional array in a ini file.
Is there a way to specify some JavaScript to execute on the OnBlur event
Is there a way to specify a Model in Django such that is ensures
Is there any way I can specify a standard or custom numeric format string
Is there a way when creating web services to specify the types to use?
In C# Is there way to specify a class to be inherited only by
I need a way to specify an application icon for a ClickOnce deployment. Basically
Is there a way to specify that a model (or app, even) should only

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.