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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:48:08+00:00 2026-05-16T17:48:08+00:00

Hello everybody i wonder: when can i use mapped by to indicate whose is

  • 0

Hello everybody i wonder: when can i use mapped by to indicate whose is owing of relationship in one-to -one or one to many – or many to many relationship mapping with EJB3 (JPA)
example
i have two table A and B
table A belong to table B
so what i place mapped by for whose table?

  • 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-16T17:48:09+00:00Added an answer on May 16, 2026 at 5:48 pm

    when can I use mapped by to indicate whose is owing of relationship in one-to -one or one to many – or many to many relationship mapping with EJB3

    A relationship can be unidirectional or bidirectional. Within a bidirectional relationship you must specify the owning side of the relationship in the other class with the mappedBy element.

    • The owning side which is responsible for propagating the update of the relationship to the database. Usually this is the side with the foreign key.
    • The inverse side maps to the owning side.

    From the JPA 1.0 specification:

    2.1.7 Entity Relationships …

    Relationships may be bidirectional or
    unidirectional. A bidirectional
    relationship has both an owning side
    and an inverse side. A unidirectional
    relationship has only an owning side.
    The owning side of a relationship
    determines the updates to the
    relationship in the database, as
    described in section 3.2.3.

    The following rules apply to
    bidirectional relationships:

    • The inverse side of a bidirectional relationship must refer to its owning
      side by use of the mappedBy element
      of the OneToOne, OneToMany, or
      ManyToMany annotation. The
      mappedBy element designates the
      property or field in the entity that
      is the owner of the relationship.
    • The many side of one-to-many / many-to-one bidirectional
      relationships must be the owning side,
      hence the mappedBy element cannot be
      specified on the ManyToOne annotation.
    • For one-to-one bidirectional relationships, the owning side
      corresponds to the side that contains
      the corresponding foreign key.
    • For many-to-many bidirectional relationships either side may be the
      owning side.

    Imagine the following model:

    @Entity
    public class Player {
    ...
        private Team team;
    
        @ManyToOne
        public Team getTeam() { return team; }
    
        ...
    } 
    

    And

    @Entity
    public class Team {
        ...    
        private Set<Player> players = new HashSet<Player();
    
        public Team() { }
    
        @OneToMany(mappedBy = "team")
        public Set<Player> getPlayers() { return players; }
    
        ...    
    }
    

    In this example, the mappedBy attribute shows that a Player instance’s team property maps to the Team instance and the Team object’s identifier will exist as a foreign key column in the PLAYER table. The owning Player side of the relationship is responsible for storing the foreign key.

    If the mappedBy is not used, the persistence provider will assume that there are two independent relationships:

    2 unidirectional relations

    Which is generally not what you want and might end up getting unexpected behavior (e.g. duplicate rows inserted with many-to-many).

    Related questions

    • In a bidirectional JPA OneToMany/ManyToOne association, what is meant by “the inverse side of the association”?
    • JPA: which side should be the owning side in a m:n relationship?

    References

    • JPA 1.0 specification
      • Section 2.1.7 “Entity Relationships”
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i cut off the last empty space? a = ['Hello ','everybody ','!
Hello can anybody solve this please I'm creating the object in the action class
Hello everybody I'm trying to replace the 'text' input type to 'password' . And
Hello everybody I've recently asked this question and I've given up with the 'replace
Hello everybody! I have a SQL (see above) and i would like to know
Hello everybody let me give you the background first: I'm working on a project
My string contain a lot of HTML entities, like this &#x22;Hello&nbsp;&lt;everybody&gt;&nbsp;there&#x22; And I want
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello again ladies and gents! OK, following on from my other question on ASP.NET
Hello I was writing a Regular Expression (first time in my life I might

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.