Hibernate: select member0_.MEMBER_ID as MEMBER_I1_3_0_, member0_.createdAt as createdA2_3_0_, member0_.deletedAt as deletedA3_3_0_, member0_.updatedAt as updatedA4_3_0_, member0_.TEAM_ID as TEAM_ID6_3_0_, member0_.USERNAME as USERNAME5_3_0_ from Member member0_ where member0_.MEMBER_ID=? Hibernate: select team0_.TEAM_ID as TEAM_ID1_5_0_, team0_.NAME as NAME2_5_0_ from Team team0_ where team0_.TEAM_ID=? findMember = class entity.Team
여기서 지연 로딩(LAZY)로 Member 객체를 조회 하였는데, Team 정보 가지 조회 되는 현상이 나타난다. 원래는 지연 로딩시 Team 정보는 Proxy로 가져오고, Team을 조회 할때 정보를 가지고 와야 지연로딩이 된다고 할 수 있다. 지연 로딩을 하려면 프록시 객체를 만들어야 하는데, Kotlin의 모든 클래스는 final이라 상속을 받을 수 없고, 일반 클래스는 open할 수 있지만 데이터 클래스는 불가능하다. JPA 표준에서는 엔티티 클래스가 final이면 안되는데 JPA 구현체로써 사용하기 때문에 작동을 한다. gradle 에 아래 와 같이 allOpen 플러그인 추가 해주면된다.
build.gradle.kts
1 2 3 4 5 6 7 8 9 10
plugins { kotlin("jvm") version "1.5.31" id("org.jetbrains.kotlin.plugin.allopen") version "1.5.31" }
Hibernate: select member0_.MEMBER_ID as MEMBER_I1_3_0_, member0_.createdAt as createdA2_3_0_, member0_.deletedAt as deletedA3_3_0_, member0_.updatedAt as updatedA4_3_0_, member0_.TEAM_ID as TEAM_ID6_3_0_, member0_.USERNAME as USERNAME5_3_0_ from Member member0_ where member0_.MEMBER_ID=? findMember = class entity.Team$HibernateProxy$pD1cOOED
Hibernate: select member0_.MEMBER_ID as MEMBER_I1_3_0_, member0_.createdAt as createdA2_3_0_, member0_.deletedAt as deletedA3_3_0_, member0_.updatedAt as updatedA4_3_0_, member0_.TEAM_ID as TEAM_ID6_3_0_, member0_.USERNAME as USERNAME5_3_0_, team1_.TEAM_ID as TEAM_ID1_5_1_, team1_.NAME as NAME2_5_1_ from Member member0_ leftouterjoin Team team1_ on member0_.TEAM_ID=team1_.TEAM_ID where member0_.MEMBER_ID=? findMember = class entity.Team