How can I use Kotlin value class?
@Entity
class User(
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
val id: UserId = UserId(0),
)
@JvmInline
value class UserId(private val value: Long)
@Service
class UserService(
private val jpqlRenderContext: JpqlRenderContext,
private val entityManager: EntityManager,
) {
fun findById(userId: UserId): User? {
val query = jpql {
select(
entity(User::class)
).from(
entity(User::class),
).where(
path(User::id).equal(userId)
)
}
return entityManager.createQuery(query, jpqlRenderContext).apply { maxResults = 1 }.resultList.firstOrNull()
}
}Custom JpqlSerializer for JpqlValue
Custom method
Notes for DTO Projection
PreviousHow can I see the generated query?NextWhat is the difference between Kotlin JDSL and jOOQ and QueryDSL?
Last updated