본문 바로가기
Jpa

Jpa One to Many Non primary key 로 연결해서 조회

by 무대포 개발자 2021. 2. 5.
728x90
반응형

Jpa One to Many Non primary key 로 연결해서 조회

// A : B = 1 : n 이라고 가정 
// A 의 testKey 와 B 의 testKey 를 조인하고자 함. 서로 non PK 임.

@Entity
public class A implements Serializable {

    private String testKey;

    @OneToMany
    @JoinColumn(name = "testKey", referencedColumnName = "testKey")
    private List<B> b = new ArrayList<>();
}

@Entity
public class B {


    private String testKey;

}

실행 도중 에러

  • spring test 중 jpa no session proxy 이런 에러가 나는데 test annotation 에 Transactional annotation 붙여 주면 됨.

댓글