Skip to content

Document default NamingStrategy and explain configuration options #616

@RobertHeim

Description

@RobertHeim

Hey, thanks for the work on the project, it works pretty well and we enjoy our work with it!

I am using spring-boot 2.5.1 with spring-boot-starter-data-r2dbc and io.r2dbc:r2dbc-postgresql.
I thought it might be related to #483 and I am not sure if it is the right repository to post the issue, so feel free to move it to spring data relational/jdbc if it is more appropriate.

I just figured out that this query:

interface TaskReviewRepository : CoroutineCrudRepository<TaskReview, Long> {
  @Query(
    """
    SELECT task_id, AVG(rating) as avgRating, COUNT(*) as reviewsCount
    FROM task_review
    WHERE task_id IN (:taskIds)
    GROUP BY task_id
  """
  )
  fun ratingSummaryWhereTaskIdIn(taskIds: Set<Long>): Flow<TaskReviewService.RatingSummaryWithTaskId>
}

and this data class

data class RatingSummaryWithTaskId(
  val taskId: Long,
  val avgRating: Double?,
  val reviewsCount: Long,
)

fails with

2021-06-30 09:22:33.240 DEBUG 7529 --- [     parallel-3] io.r2dbc.postgresql.PARAM                : Bind parameter [0] to: 1
2021-06-30 09:22:33.246 DEBUG 7529 --- [     parallel-3] io.r2dbc.postgresql.QUERY                : Executing query: 
    SELECT task_id, AVG(rating) as avgRating, COUNT(*) as reviewsCount
    FROM task_review
    WHERE task_id IN ($1)
    GROUP BY task_id
// ...
org.springframework.data.mapping.model.MappingInstantiationException: Failed to instantiate com.example.tasks.TaskReviewService$RatingSummaryWithTaskId using constructor fun <init>(kotlin.Long, kotlin.Double?, kotlin.Long): com.example.tasks.TaskReviewService.RatingSummaryWithTaskId with arguments 1,null,null
    at org.springframework.data.mapping.model.ClassGeneratingEntityInstantiator$EntityInstantiatorAdapter.createInstance(ClassGeneratingEntityInstantiator.java:246) ~[spring-data-commons-2.5.1.jar:2.5.1]
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
// ...
Caused by: java.lang.IllegalArgumentException: Parameter reviewsCount must not be null!

while this query (snake case)

SELECT task_id, AVG(rating) as avg_rating, COUNT(*) as reviews_count
FROM task_review
WHERE task_id IN (:taskIds)
GROUP BY task_id

works fine.

I suggest supporting camelCase in the alias for selected columns or at least to provide an error message that camelCase is not supported, because it took me several hours to figure this out.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions