hibernate @OneToMany(mappedBy=

Posted on 2009-12-18
Last Modified: 2013-11-11
In the docs for hibernate I was reading:

Since many to one are (almost) always the owner side of a bidirectional relationship in the EJB3 spec, the one to many association is annotated by @OneToMany( mappedBy=... )

public class Troop {
    public Set<Soldier> getSoldiers() {

public class Soldier {
    private Troop troop;
    public Troop getTroop() {

My question:
the mappedBy is pointing at the name of the variable "troop" and not the class name right?
Question by:wrynn
    LVL 11

    Accepted Solution

    Hi wrynn,

    Yes. Troop has a bidirectional one to many relationship with Soldier through the troop property.

    Hope this help,
    LVL 20

    Assisted Solution

    by:Sathish David Kumar N
    yes ur correct
    that menntion the property name !!

    for example id is property of the bean u going to map @OneToMany(mappedBy="troop")
     for id only not for the bean class !!

    Author Comment

    thanks guys!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Suggested Solutions

    Title # Comments Views Activity
    Convert ArrayList of custom objects to JSON 4 44
    copyEndy  challenge 15 37
    Increment alphanumeric sequence 6 52
    array11 challenge 16 40
    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now