Skip to content

Commit

Permalink
docs: add dto projection docs for value class
Browse files Browse the repository at this point in the history
Co-authored-by: Jake Son <[email protected]>
  • Loading branch information
erie0210 and jbl428 committed May 31, 2024
1 parent 512a600 commit 0eb4a45
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/ko/faq/how-do-i-use-kotlin-value-class.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,27 @@ class CustomJpql : Jpql() {
}
}
```

### DTO Projection 시 주의사항

DTO Projection 에서 value class를 사용하는 경우 해당 프로퍼티가 nullable 한 경우에 지원되지 않습니다.
따라서 DTO Projection에서 직접 value class를 사용하는 것보다, 기본 자료형을 사용하고 조회 후에 변환하는 것을 권장합니다.

```kotlin
data class ResponseDto(
private val rawId: Long,
) {
val id: UserId
get() = UserId(rawId)
}

val query = jpql(CustomJpql) {
selectNew<ResponseDto>(
entity(User::id)
).from(
entity(User::class),
).where(
path(User::id).equalValue(userId)
)
}
```

0 comments on commit 0eb4a45

Please sign in to comment.