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

import java.util.*; public class Test { public static void main(String[] args) { Map<String,String> map
Edit 5/11/2011: I guess it's a bit worse than what's below; in my deployed
A Party can have one or more Contact objects. I want to select all
I have created a Conceptual Model in my project using a table in my
I have a C program below written on UNIX. I am getting segmentation fault.
Im developing a web application(J2EE,Struts2,JSP,Tomcat) I want to hide the .jsp extension from webpages.
I'm working on an automatic mapping framework built on top of Dozer. I won't
I am new to ExtJs and I am using ExtJs4. Now As shown in
I'm having some problems with the SqlNamedQuery attribute that has been added to the
I am new to JSF and Spring. I am trying to use Spring Security

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.