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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:07:48+00:00 2026-06-15T16:07:48+00:00

In my current project I have a inheritance structure that looks like this: @Entity

  • 0

In my current project I have a inheritance structure that looks like this:

@Entity
@Table(name="groups")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorValue("G")
@DiscriminatorColumn(name="group_type")
public class Group{  //some annotations removed 
    private Long id;
    private String name;
    private Set<Subject> subjects;
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name="parent_group_id")
    private Group parent;            #####  tree parent  ####
@OneToMany(cascade=CascadeType.ALL, mappedBy="parent")
    private Set<Group> subGroups;    ##### tree children #####
        ...
}

My Group objects can have kind of a tree like structure by containing a list of other Group objects.
As some groups are a bit special, there is a second class that extends this class:

   @Entity
   @DiscriminatorValue("C")
   @Table(name="fix_groups")
   public class FixGroup extends Group{
        private Layout lay;
        private Set<Person> instr;
            ...
    }

I tried to use a joined multi table approach (as described here: http://en.wikibooks.org/wiki/Java_Persistence/Inheritance#Joined.2C_Multiple_Table_Inheritance) but it seems not to work with a non abstract superclass like Group!
I get the following exception:

Caused by: java.lang.ClassCastException: org.hibernate.mapping.JoinedSubclass 
cannot be cast to org.hibernate.mapping.RootClass

Is there a solution apart from declaring Group as abstract and making a new class Group2 that only extends it?
And if I did so, would this self-reference Set<Group> subGroups still cause problems?

  • 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-15T16:07:50+00:00Added an answer on June 15, 2026 at 4:07 pm

    I was able to cause this error by setting the ID in the subclass when it is already mapped in the parent class (in this case Group). For example in the parent class:

    @Entity
    @Table(name="groups")
    @Inheritance(strategy=InheritanceType.JOINED)
    public class Group {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Column(name = "ID")
        private Long id;
    ...
    

    and then setting the id in the subclass like so:

    @Entity
    @Table(name="sub_groups")
    public class SubGroup extends Group {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Column(name = "ID")
        private Long id;
    ...
    

    In this case, Group does not need to be abstract, but you can’t define the id on the subclass.

    Also, as a side note, if you are using Hibernate with an inheritance of type “join”, then the discriminator column and value are not needed. Hibernate only utilizes those if using a single table. Please reference this post for further information:

    Hibernate 4: persisting InheritanceType.JOINED discriminator column values

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

Sidebar

Related Questions

In my current project we have a large repository of content that was originally
I have a short question. Im my current project I'm using LINQ-to-SQl. That is
In my current django project I have a model that stores very long strings
In my current project I have a few different interfaces that require me to
In my current project I have a custom ViewData that has (amongst others) the
In my current project I have an ArrayList of PVectors that store xyz coordinates
For a current MVC3 project I have a model that has multiple pages for
In my current project I have an entity which can be published to other
within my current project file I have a user control that has a storyboard
I have my current project set up so that I can query across two

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.