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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:21:29+00:00 2026-06-16T13:21:29+00:00

I met the following ORM problem: I am having two classes A and B

  • 0

I met the following ORM problem:

I am having two classes A and B who both are having a Set of class C:

class A {
  @Id
  @GeneratedValue
  private long id;

  @OneToMany
  private Set<C> cSet;
}

class B {
  @Id
  @GeneratedValue
  private long id;

  @OneToMany
  private Set<C> cSet;
}

class C {
  @Id
  @GeneratedValue
  private long id;
}

One idea I had was using a MappedSuperclass for C and having two extended classes that are each referenced in either A or B. But from an object oriented point of view this is not the nicest approach although I could use the superclass type in order to work with them.

Is there any nicer way to realize this model?

Thanks,
Benjamin

  • 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-16T13:21:31+00:00Added an answer on June 16, 2026 at 1:21 pm

    If you don’t specify any mapping annotation (i.e. JoinColumn or JoinTable), it will use a join table for each association.

    You will thus have the following tables:

    A : id
    B : id
    C : id
    A_C : a_id, c_id (where c_id is unique)
    B_C : a_id, c_id (where c_id is unique)
    

    The alternative if to annotate each set with a JoinColumn annotation:

    class A {
        @OneToMany
        @JoinColumn(name = "a_id")
        private Set<C> cSet;
    }
    
    class B {
       @OneToMany
       @JoinColumn(name = "b_id")
       private Set<C> cSet;
    }
    

    And you will thus have the following tables:

    A : id
    B : id
    C : id, a_id, b_id
    

    This is of course described in the documentation.

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

Sidebar

Related Questions

I met a problem when trying @Singleton of Guice: import com.google.inject.Singleton; @Singleton public class
In Programming Pearls I have met the following problem. The question is this: print
I met a very odd problem. The following code doesn't run anticipated. static IEnumerable<int>
Following this question , I've met another problem where the request just doesn't go
I met the following problem. After drawing line on several canvas of the same
Today I was met the following code block: #include <iostream> using namespace std; char
I met strange problem. I have never work with Devise gem before. So, i
I met a problem when Call to a member function combinestring() on a non-object.
I met a problem which is very strange, my company uses Visual Source Safe
I met with an xml tranformation problem. After applying a suggested muenchian grouping to

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.