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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:58:58+00:00 2026-05-31T01:58:58+00:00

Hi i am learning about @ManyToMany relationship mapping using JPA. I more or less

  • 0

Hi i am learning about @ManyToMany relationship mapping using JPA.
I more or less understand how it works, but i have a doubt. Let me show you first this code where i do some mapping:

@Entity
public class EntityE implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long eId;
    @ManyToMany
    @JoinTable(joinColumns =
    @JoinColumn(name = "eId"), inverseJoinColumns =
    @JoinColumn(name = "fId"))
    private Collection<EntityF> entityFs;
    //...
}

Also see this other entity:

@Entity
public class EntityF implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long fId;    
    private Collection<EntityE> entityEs;
    //...
 }

This is what i get in the database:

enter image description here

My doubts are:

-I want to create a @ManyToMany relationship where EntityE is the owner of the relationship, is this approach correct?

-I want the relationship to be unidirectional, so it is supposed to create just one mediator table called EntityB_EntityF. But for some reason it creates also a second table called EntityF_EntityE. I dont understand why is that?,Is that normal? and if not how should i fix it?

  • 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-31T01:58:59+00:00Added an answer on May 31, 2026 at 1:58 am

    Ok i just got the answer after doing some little experiment.I think it is correct, it now works as i spected.
    What i did was, add a name for the relationship, because for some strange reason if you don’t specify the name it creates a bidirectional relationship.

    See this code fixed it:

    @Entity
    public class EntityE implements Serializable {
    
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long eId;
        @ManyToMany
        @JoinTable(name="entitye_entityf",joinColumns =
        @JoinColumn(name = "eId"), inverseJoinColumns =
        @JoinColumn(name = "fId"))
        private Collection<EntityF> entityFs;
    

    Here is the other entity.

    @Entity
    public class EntityF implements Serializable {
    
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long fId; 
        @ManyToMany
        @JoinTable(name="entitye_entityf",joinColumns =
        @JoinColumn(name = "fId"), inverseJoinColumns =
        @JoinColumn(name = "eId"))
        private Collection<EntityE> entityEs;
    

    So as you can see from the image, managed to solve my doubts. I hope this answer can be useful for someone else as well.

    enter image description here

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

Sidebar

Related Questions

I have been learning about the basics of C# but haven't come across a
Since I have started learning about rendering to a texture I grew to understand
I've just been learning about master pages in ASP.NET 2.0. They sound great, but
I am just learning about app.config in respect of creating custom sections. I have
I'm just learning about SVG, and it seems great but I'm not sure about
Learning about threading is fascinating no doubt and there are some really good resources
I'm learning about how to manipulate the Membership class. I have added the Membership
I'm just learning about SproutCore now, seems great. But I can't find a good
I'm learning about ternary operators now. I got the basics down, but then I
learning about loops (still a beginner) in VB.net. I have got the below code

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.