0

난 최대 절전 모드에 새로 온 사람과 내가 주석최대 절전 모드 ManyToOne - OneToMany 루프?

이 내 두 개의 테이블이 있습니다 사용

enter image description here

이 내 표 "페르소나"

@Entity 
@Table(name = "persona") 
public class Persona implements java.io.Serializable { 

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    @Column(name = "codigo", unique = true, nullable = false) 
    private int codigo; 

    @ManyToOne(fetch = FetchType.LAZY) 
    @JoinColumn(name = "codTipoIdent", nullable = false) 
    private TipoIdentificacion tipoIdentificacion; 

    .... 

이 내 두 번째 테이블입니다을 "TipoIdentificacion"

@Entity 
@Table(name = "tipoIdentificacion") 
public class TipoIdentificacion implements java.io.Serializable { 

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    @Column(name = "codigo", unique = true, nullable = false) 
    private int codigo; 

    @Column(name = "nombre", nullable = false) 
    private String nombre; 

    @Column(name = "siglas", nullable = false) 
    private String siglas; 

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "tipoIdentificacion")  
    private Set<Persona> persona = new HashSet<Persona>(0); 

"페르소나"의 기본 키는 "코모"이고 "TipoIdentificacion"은 페르소나 (codTipoIdent)의 FK입니다.

모든 것이 멋지게 보이며, 내 웹 앱에서 아주 잘 만들었지 만 내가 요청에 대해 "TipoIdentificacion"의 목록을 디버깅 할 때 왜

enter image description here

는 루프를 만들 것 같습니다?

+1

두 대의 자동차가 있습니다. 자동차 소유자가 너야. 너는 2 대의 자동차를 가지고있다. 그리고 자동차 소유자는 당신입니다. 그리고 당신은 2 대의 자동차를 가지고 있습니다 ... 양방향 협회가있을 때 완전히 기대됩니다. –

+0

그래, 그게 더 많아, 감사합니다.) 고맙습니다. – MitoCode

답변

0

여기서는 양방향 관계를 정의 했으므로 예상되는 동작입니다. 단방향 관계를 생성하여이를 피할 수 있습니다. -

http://webdev.apl.jhu.edu/~jcs/ejava-javaee/coursedocs/605-784-site/docs/content/html/jpa-relationex-many2one-uni.html 
관련 문제