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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:57:30+00:00 2026-05-24T10:57:30+00:00

Given those entities : class SportTeam { @Id @GeneratedValue long id; @OneToMany private Set<PLayer>

  • 0

Given those entities :

class SportTeam {
   @Id
   @GeneratedValue
   long id;
   @OneToMany
   private Set<PLayer> players;
   @OneToMany
   private Set<Player> stars;
}
// A sport team can have multiple players and some of those players can be stars.

class Player {
   @Id
   @GeneratedValue
   long id;
   (...)
}

Here is the DDL generated by Hibernate :

CREATE TABLE sportteam
(
  id bigint NOT NULL,
  (...)
  CONSTRAINT sportteam_pkey PRIMARY KEY (id)
)

CREATE TABLE sportteam_player
(
  sportteam_id bigint NOT NULL,
  player_id bigint NOT NULL,
  star_id bigint NOT NULL,
  CONSTRAINT sportteam_player_pkey PRIMARY KEY (sportteam_id, star_id),
  CONSTRAINT fk6cf55c6645d973bc FOREIGN KEY (player_id)
  REFERENCES player (id) MATCH SIMPLE
  ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT fk6cf55c66ca1af8b8 FOREIGN KEY (star_id)
  REFERENCES player (id) MATCH SIMPLE
  ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT sportteam_player_star_id_key UNIQUE (star_id),
  CONSTRAINT sportteam_player_player_id_key UNIQUE (player_id)
)    


CREATE TABLE player
(
   id bigint NOT NULL,
   (...)
   CONSTRAINT player_pkey PRIMARY KEY (id)
)

I would prefer the sportteam_player looks like this :

CREATE TABLE sportteam_player
(
  sportteam_id bigint NOT NULL,
  player_id bigint NOT NULL,
  is_star boolean DEFAULT 'FALSE',
  CONSTRAINT sportteam_player_pkey PRIMARY KEY (sportteam_id, player_id),
  CONSTRAINT fk6cf55c6645d973bc FOREIGN KEY (player_id)
  REFERENCES player (id) MATCH SIMPLE
  ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT fk6cf55c66ca1af8b8 FOREIGN KEY (sportteam_id)
  REFERENCES sportteam (id) MATCH SIMPLE
  ON UPDATE NO ACTION ON DELETE NO ACTION
)    

How can I do ?

  • 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-24T10:57:31+00:00Added an answer on May 24, 2026 at 10:57 am

    It is not feasible to model JPA relations like that. You assume that Team-to-Star is a one-to-many relation in a relational database sense. It certainly is some kind of a stereotype relation, but it is based on the property of a player that is a star or not. So:

    class Player {
      @Id
      @GeneratedValue
      long id;
      @Column(name = “is_star”, columnDefinition="boolean default false")
      boolean star;
      (...)
    }
    
    class SportTeam {
      @Id
      @GeneratedValue
      long id;
      @OneToMany
      private Set<PLayer> players;
    
      public Collection<Player> getStars() {
        // return your stars here, filter through players.
        // if you want you can do caching, but remember to set the field to @Transient
        // so that Hibernate does not think, it could be a relation
      }
    }
    

    Why would I do that? In the SportTeam you have loaded all of the Players already anyway. No reason to do that via database. Being a star is a property of the star and if you need the list in the SportTeam class, it is just a different view on the existing players.

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

Sidebar

Related Questions

Given the entities, class A { B DefaultB { get; set; } C DefaultC
Given a list of names for variables, I want to set those variables to
Given that I have a table that holds vehicle information and one of those
One of those classic programming interview questions... You are given two marbles, and told
This is easier to explain with an example. Given these two classes: public class
Assuming these objects... class MyClass { int ID {get;set;} string Name {get;set;} List<MyOtherClass> Things
Given the class below does anyone know why EclipseLink implementation of JPA fails to
public class Car { public string SomeProperty { get; set; } public Manufacturer Manufacturer
I have these entities in my database For a given Job , I want
I have a class that uses filesystem entities to manipulate data. We have several

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.