?
Solved

hibernate @OneToMany(mappedBy=

Posted on 2009-12-18
3
Medium Priority
?
1,197 Views
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=... )

@Entity
public class Troop {
    @OneToMany(mappedBy="troop")
    public Set<Soldier> getSoldiers() {
    ...
}

@Entity
public class Soldier {
    private Troop troop;
    @ManyToOne
    @JoinColumn(name="troop_fk")
    public Troop getTroop() {
    ...
}              

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

Accepted Solution

by:
sompol_kiatkamolchai earned 1600 total points
ID: 26086203
Hi wrynn,

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

Hope this help,
Sompol
0
 
LVL 20

Assisted Solution

by:Sathish David Kumar N
Sathish David  Kumar N earned 400 total points
ID: 26086356
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 !!
0
 

Author Comment

by:wrynn
ID: 26089472
thanks guys!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month16 days, 17 hours left to enroll

864 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