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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:37:50+00:00 2026-05-28T16:37:50+00:00

I have a classes as follows: AnimalClass [Id, Name, Set<Tag>] | +– FishClass [FishSpecific]

  • 0

I have a classes as follows:

AnimalClass [Id, Name, Set<Tag>]
|
+-- FishClass [FishSpecific]
+-- MammalClass [MammalSpecific]

Tag [Name]

So any animal can have any number of associated tags.

For that I use in AnimalClass:

@JoinTable(name="Animal_Tag")
@JoinColumn(name="animal_id", referencedColumnName="id", nullable=false)
@OneToMany(cascade=CascadeType.ALL)
@Getter
protected Set<Tag> tags = new HashSet<Tag>();

My problem is that, Hibernate creates the m-n table as:

 Animal_Tag [FishClass_id, MammalClass_id, Tag_id]. 

I would prefer to have some kind of enumeration as:

 Animal_Tag [Animal_id, AnimalTypeEnumeration[ Fish | Mammal ], Tag_id].

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-05-28T16:37:51+00:00Added an answer on May 28, 2026 at 4:37 pm

    I suspect you can’t do that with a mapped superclass.

    The thing about a mapped superclass is that it doesn’t define a persistent type. It defines a sort of template for a persistent types. Every time you define a subclass of it which is annotated @Entity, you create an instance of the template, but in the data model, there is no relationship between those types. The use of the mapped superclass is almost a shortcut for a copy-and-paste of a given set of fields into the new entity class.

    So, as far as the data model is concerned, there is no possible animal_id, because there is no such type as animal. Only fish and mammal exist in the database.

    Can you make AnimalClass an entity instead of a mapped superclass? If you use the table-per-class inheritance strategy, you won’t need to create a table for it. But it will make animal a type, which means the ORM will be able to use an animal_id.

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

Sidebar

Related Questions

Let's say I have three classes set up as follows: abstract Class A {
In my code I have three classes as follows: Forum , Forum::Thread and Forum::Post
I have two classes Address and Employee as follows: public class Address { public
New to FluentNHibernate =D I have a parent/children classes as follows: public class Parent
I have two Java classes: B, which extends another class A, as follows :
I have seen some C++ classes with a destructor defined as follows: class someClass
I have classes which have automatic properties only like public customerName {get; set;}. They
Suppose I have 3 classes as follows (as this is an example, it will
I have User and Address classes as follows: class User { ... ... @OneToOne(
Say I have two type classes defined as follows that are identical in function

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.