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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:01:08+00:00 2026-05-20T18:01:08+00:00

My mappings are below. Here is the base class for all classes. There is

  • 0

My mappings are below.

Here is the base class for all classes. There is no table for this class. All subclasses user id as their PK.

@MappedSuperclass
public abstract class Model {
    private Long id;

    @Id
    @GeneratedValue(strategy=GenerationType.Sequence, generator="myGenerator")
    public Long getId() { return id; }
}

A class for Comments that has its own table, with columns for all the fields in Model

@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@Table(name = "COMMENT")
@SequenceGenerator(name="myGenerator", sequenceName="COMMENT_SEQ", allocationSize=1)
public class Comment extends Model {
    //some data
}

A subclass of Comment that also has its own table, with columns for all the fields in Comment and Model

@Entity
@Table(name = "ORDER_COMMENT")
@SequenceGenerator(name="myGenerator", sequenceName="ORDER_COMMENT_SEQ", allocationSize=1)
public class OrderComment extends Model {
    //some data
}

This class has its own table and can have one to many order comments.

@Entity
@Table(name="ORDER")
@SequenceGenerator(name="myGenerator", sequenceName="ORDER_SEQ", allocationSize=1)
public class Order extends Model {
    private Set<OrderComment> = new HashSet<OrderComment>();

    @OneToMany
    @JoinColumn(name="ORDER_ID")
    public Set<OrderComment> getComments() { return comments; }
}

The issue is that when I add a new OrderComment to an Order, Hibernate selects the id from the sequence for Comment instead of the sequence for OrderComment.

Any ideas on why this is happening and what I can change to fix this issue? Or is there a better way to map this?

  • 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-20T18:01:09+00:00Added an answer on May 20, 2026 at 6:01 pm

    A SequenceGenerator is globally identified by it’s name, hence you can only have one called “myGenerator”.

    If you wish to use your identifier on a global variable, with @GeneratedValue, you’ll need to define a single @SequenceGenerator and use a single sequence for all your tables.

    Alternatively, you could keep an abstract getId method at your superclass and implement it on every subclass: hibernate is happy and you’ll have a uniform way to reach your id’s.

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

Sidebar

Related Questions

I have 2 mappings like this: <hibernate-mapping> <class name=A table=A> <id name=code column=aCode type=integer>
What tool is there for generating C# classes from NHibernate mappings files?
When manipulating Handler Mappings using the Microsoft.Web.Administration namespace, is there a way to remove
LINQ to SQL allows table mappings to automatically convert back and forth to Enums
When using fluent configuration to specify fluent mappings like this: .Mappings(m => m.FluentMappings.AddFromAssembly(typeof(UserMapping).Assembly)) At
I have the following models & mappings (code snippets further below). One Competition has
I'm having a problem here. How you can see on the code below, I
I've setup a one-to-many/many-to-one bi-directional mapping relationship for a User class and a Pet
The below definition is taken from Hibernate association mapping tutorial here Each book is
I have a 'User' Entity that contains an 'Address' Value Object. I have this

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.