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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:50:30+00:00 2026-05-27T17:50:30+00:00

i have a generated table called employee , as a relation between two tables:

  • 0

i have a generated table called employee, as a relation between two tables:

Person ,
MedicalCompany

and i was wondering how to make manyToMany relation between this generated table and another table, something like:

@ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "employee_role", joinColumns = { @JoinColumn(name = "employee_id") }, inverseJoinColumns = { @JoinColumn(name = "role_id") })
    private Set<Role> roles = new HashSet<Role>(0);

1- Generated Table:

@SuppressWarnings("serial")
@Entity
@Table(name = "employee")
@AssociationOverrides(value = {
        @AssociationOverride(name = "pk.medicalCompany", joinColumns = @JoinColumn(name = "company_id", referencedColumnName = "id")),
        @AssociationOverride(name = "pk.person", joinColumns = @JoinColumn(name = "employee_id", referencedColumnName = "person_id")),
        @AssociationOverride(name = "pk.titleText"),
        @AssociationOverride(name = "pk.employeeManager") })
public class Employee implements Serializable {

    @EmbeddedId
    private EmployeeCompanyId pk = new EmployeeCompanyId();

    @Transient
    public void setEmployeeManager(long employeeManager) {
        this.pk.setEmployeeManager(employeeManager);
    }

    public long getEmployeeManager() {
        return pk.getEmployeeManager();
    }

    @Transient
    public void setTitleText(String titleText) {
        this.pk.setTitleText(titleText);
    }

    public String getTitleText() {
        return pk.getTitleText();
    }

    public void setPerson(Person person) {
        this.pk.setPerson(person);
    }

    @Transient
    public Person getPerson() {
        return this.pk.getPerson();
    }

    public void setMedicalCompany(MedicalCompany medicalCompany) {
        this.pk.setMedicalCompany(medicalCompany);
    }

    @Transient
    public MedicalCompany getMedicalCompany() {
        return this.pk.getMedicalCompany();
    }

    public void setPk(EmployeeCompanyId pk) {
        this.pk = pk;
    }

    public EmployeeCompanyId getPk() {
        return pk;
    }

}

2- EmployeeCompanyId:

@SuppressWarnings("serial")
@Embeddable
public class EmployeeCompanyId implements Serializable {

    @ManyToOne
    private Person person;

    @ManyToOne
    private MedicalCompany medicalCompany;

    @Size(max = 150, message = "{long.value}")
    @Column(name = "title_text", length = 150, nullable = true)
    private String titleText;

    @Column(name = "employee_manager")
    private long employeeManager;

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    public MedicalCompany getMedicalCompany() {
        return medicalCompany;
    }

    public void setMedicalCompany(MedicalCompany medicalCompany) {
        this.medicalCompany = medicalCompany;
    }

    public String getTitleText() {
        return titleText;
    }

    public void setTitleText(String titleText) {
        this.titleText = titleText;
    }

    public long getEmployeeManager() {
        return employeeManager;
    }

    public void setEmployeeManager(long employeeManager) {
        this.employeeManager = employeeManager;
    }

}
  • 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-27T17:50:31+00:00Added an answer on May 27, 2026 at 5:50 pm

    You can’t have relationships within @Embeddable which is an @EmbeddedId. You can have relationships only in regular @Embeddable.


    JPA 2.0 FR spec, 11.1.15 EmbeddedId Annotation:

    Relationship mappings defined within an embedded id class are not
    supported
    .

    Hibernate 3.5 doc, 2.2.3.2.1. @EmbeddedId property

    In the embedded id object, the association is represented as the identifier of the associated entity. But you can link its value to a regular association in the entity via the @MapsId annotation.


    The least you can do is to use primary key types in embeddable. You can then map them to the entities in which the embeddable exist. In other words you can have something like:

    @Embeddable
    public class EmployeeCompanyId implements Serializable {
    
        private int personId;
    
        // ...
    }
    
    @Entity
    public class Employee {
    
        @EmbeddedId
        private EmployeeCompanyId pk = new EmployeeCompanyId();
    
        @MapsId("personId")
        @ManyToOne
        private Person person;
    
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a generated DataSet with bunch of tables. In one table I have
I have two classes generated by LINQ2SQL both from the same table so they
I have a table called Group_Focus and when we generated our code with Subsonic
Suppose I have a MySQL table called MyTable, that looks like this: +----+------+-------+ |
I have a table called ticket in which I want to swap two rows
I have a table called Foo and I have two columns: Lorem and Ipsum,
I have two classes. One is called Employee and the other EmployeeDetails that has
I'm working on a web page where I have a dynamically generated table where
I have a table that's generated by a normal PHP loop. What I want
I have a DB table in which each row has a randomly generated primary

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.