목록JPA (1)
Arthur's Blog
@Query에서 FK로 객체를 찾는 법
class User { @Id private String username; @ManyToOne private School school; } @Query(select u from User u where user.school = :schoolName) List findBySchool(@Param('schoolName')String schoolName); 위 Repository interface는 얼핏 보면 그럴싸 해보이지만 실제로 구동을 시켜보면 500에러와 함께 application이 소리를 지른다. 그 이유는 school은 객체로 맵핑이 되어있기 때문인데 실제 작동을 시키려면 @Query(select u from User u where user.school.schoolName = :schoolName)..
Backend/Spring Boot
2023. 6. 23. 08:48