Here:
Hi all,
Here:
http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/It is written that:
Quote:
many to one are (almost) always the owner side of a bidirectional relationship
In the Doc sample the many to one is the Soldier entity is that so?
Way Soldier is the owner side of bidirectional relationship?
When you save a Troop object you would like to save its entire Soldier's automatically, so Troop will always be the owner side of the relationship, am I correct?
Code:
2.2.5.3.1.1. Bidirectional
Since many to one are (almost) always the owner side of a bidirectional relationship in the JPA 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 {
@ManyToOne
@JoinColumn(name="troop_fk")
public Troop getTroop() {
...
}