Skip to content

Override query limit in R2dbcEntityTemplate.selectOne only if the query has no limit #758

@RobertHeim

Description

@RobertHeim

Using selectOne on a query with multiple results obviously throws a "non unique result" exception. When the query is limited to 1, it still throws:

return template.selectOne(
  Query.query(
    Criteria.where("notificationId").isEqual(notificationId)
  )
    .sort(Sort.by("serverTimestamp").ascending())
    .limit(1), // <----
  MyEntity::class.java
)
  .awaitSingleOrNull()

In the query log I see that the limit is set to 2 instead of 1.

org.springframework.dao.IncorrectResultSizeDataAccessException: Query [SELECT my_entity.* FROM my_entity WHERE my_entity.notification_id = $1 ORDER BY server_timestamp ASC LIMIT 2] returned non unique result.

This makes me think it's a bug because the limit seems to be ignored?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions