Is EJB3 displayed? whose possession is the mapping OR?

Greetings to everyone I wonder: when can I use matching to indicate whose relationship is related to a one-on-one relationship or from one to another, or from many to many relationship comparisons with EJB3 (JPA) example I have two tables A and B table A refers to table B so I drew a map for the table?

+3
source share
2 answers

when I can use matched to indicate whose relationship is one-to-one or one-to-many, or from many to many relationships with EJB3

. mappedBy.

  • , . .
  • .

JPA 1.0:

2.1.7 ...

. . . , 3.2.3.

:

  • mappedBy OneToOne, OneToMany ManyToMany . mappedBy , .
  • "--/--" , mappedBy ManyToOne.
  • - , .
  • .

:

@Entity
public class Player {
...
    private Team team;

    @ManyToOne
    public Team getTeam() { return team; }

    ...
} 

@Entity
public class Team {
    ...    
    private Set<Player> players = new HashSet<Player();

    public Team() { }

    @OneToMany(mappedBy = "team")
    public Set<Player> getPlayers() { return players; }

    ...    
}

mappedBy , Player instance team team, team PLAYER. Player .

mappedBy , , :

2 unidirectional relations

, , , (, , --).

  • JPA 1.0
    • 2.1.7 " "
+6

mappedBy , .

, " " A B:

@Entity
public class A {

    @OneToOne
    @JoinColumn
    private B b;

    // Code removed for clarity

}

A B. " " . , B A, , , mappedBy:

@Entity
public class B {

    @OneToOne(mappedBy="b")
    private A a;

    // Code removed for clarity

}

mappedBy " " ", A, " b ".

, , , , . , -, .

+2

Source: https://habr.com/ru/post/1762809/


All Articles