Skip to content

Interface projections should be backed by Map instead of the entity object #1394

Closed as not planned
@eduanb

Description

@eduanb

With Spring Data R2DBC, it seems like a projection in a repository always creates the entity object and applies the projection on top of it.

This example:

@Table(""""user"""")
data class User(
    @Id
    val id: Long,
    val firstName: String,
    val lastName: String
)

interface UserRepo: CoroutineCrudRepository<User, Long> {
    @Query("""select concat(first_name, ' ', last_name) as full_name from "user" """)
    fun findAllFullName(): Flow<UserFullName>
}

interface UserFullName {
    val fullName: String
}

Will always result in this error:
Failed to instantiate com.example.r2dbc.User using constructor fun (kotlin.Long, kotlin.String, kotlin.String).

This is a trivial example to show the error, but since Spring Data R2DBC does not support joins/relationships, actual projections could contain results from joining tables which cannot be represented in an entity presently.

Is there any reason why the entity mapping applies and the projection doesn't proxy through to the raw io.r2dbc.spi.Row?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions