-
Notifications
You must be signed in to change notification settings - Fork 684
Apply Kotlin Value Class unboxing for repository invocations #2868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This should also apply to audit types. @JvmInline
value class Auditor(val str: String)
data class MyEntity(
@Id val id: Long = 0L,
val name: String,
@CreatedBy val createdBy: Auditor = Auditor("UNKNOWN"),
)
@Configuration
@EnableR2dbcAuditing
class AuditConfig {
@Bean
fun auditorAware(): ReactiveAuditorAware<Auditor> = ReactiveAuditorAware {
Auditor("test")
}
} In Spring Data 3.2.5, when setting audit parameters, exception throws like
|
I've had success with the following workaround for now: @Repository
interface ContactRepository : JpaRepository<Contact, Contact.Ref> {
@Query("select count(c) > 0 from Contact c where c._id = :id")
override fun existsById(id: Contact.Ref): Boolean
@Query("select c from Contact c where c._id = :id")
override fun findById(id: Contact.Ref): Optional<Contact>
} Where |
Another place for unboxing that should be considered is collections, because value classes are always wrapped when used as generic types. E.g.: value class UserId(val value: String)
data class Entity(
@Id
val from: UserId,
val to: UserId,
)
interface EntityRepository : Repository<Entity, UserId> {
fun findAllByToIn(to: List<UserId>): List<Entity>
} |
we currently have the same issue. is there any solution work-around for this already? |
When defining a value class as Id type (
MyRepository : Repository<MyEntity, MyValueClass>
), calls that pass on Value class instances must apply wrapping/unwrapping according to the rules of how Kotlin expands Value class types.It would be great to have an interceptor that translates arguments for
findById(ID)
calls, essentially all methods that acceptID
.See also spring-projects/spring-data-jpa#2840
The text was updated successfully, but these errors were encountered: