728x90
@EntityGraph
JPQL์ ํ์น ์กฐ์ธ์ ์กฐ๊ธ ๋ ํธํ๊ฒ ์ธ ์ ์๊ฒ DATA JPA์์ ์ ๊ณตํด์ฃผ๋ ๊ธฐ๋ฅ์ ๋๋ค.
@EntityGraph(attributePaths = {"ํ์น์กฐ์ธํ ์ํฐํฐ ํ๋๋ช 1", "ํ๋๋ช 2", ...})
์์
@Entity
@Getter
@Table(name = "member")
class Member {
@Id @Column(name = "member_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String username;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "team_id")
private Team team;
}
public interface MemberRepository extends JpaRepository<Member, Long> {
//๊ณตํต ๋ฉ์๋ ์ค๋ฒ๋ผ์ด๋
@Override
@EntityGraph(attributePaths = {"team"})
List<Member> findAll();
//JPQL + ์ํฐํฐ ๊ทธ๋ํ
@EntityGraph(attributePaths = {"team"})
@Query("select m from Member m")
List<Member> findMemberEntityGraph();
//๋ฉ์๋ ์ด๋ฆ์ผ๋ก ์ฟผ๋ฆฌ์์ ํนํ ํธ๋ฆฌํ๋ค.
@EntityGraph(attributePaths = {"team"})
List<Member> findByUsername(String username);
}
Reference
728x90
'๐๏ธ Spring > JPA' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Spring Data JPA] ๋ฝ(Lock) ์ฌ์ฉํ๊ธฐ (0) | 2022.07.28 |
---|---|
[Spring Data JPA] ์ฝ๊ธฐ ์ ์ฉ ์ฟผ๋ฆฌ ๋ง๋ค๊ธฐ (JPA Hint) (0) | 2022.07.28 |
[Spring Data JPA] ๋ฒํฌ ์ฐ์ฐ (0) | 2022.07.28 |
[JPA] ํ์ด์ง ์ ๋ฆฌ (JPA, Data JPA, QueryDSL) (1) | 2022.07.28 |
[Spring Data JPA] - ๋ฐํ ํ์ ์ ์ข ๋ฅ (0) | 2022.07.28 |