Skip to content

Nested aggregations that used to work with 1.3.6 no longer work with 1.4.0 #695

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

Closed
mariusstaicu opened this issue Dec 10, 2021 · 5 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@mariusstaicu
Copy link

After upgrading spring-data-r2dbc from 1.3.6 to 1.4.0 (spring boot upgrade from 2.5.6 to 3.6.1), the queries with nested aggregate objects no longer work.

example:

data class TimezoneAgg(
    val device: DeviceAgg,
    val name: DevicePropertyName,

    @Column("value")
    val timezone: Long
)

data class DeviceAgg(
    val id: Long,
    val name: String
)

interface DevicePropertyRepository : CoroutineCrudRepository<DeviceProperty, Long> {
    @Query("""select d.id as device_id, d.name as device_name, dp.name, dp.value from device d inner join device_property dp 
        on d.id = dp.device_id where dp.name = 'TIMEZONE' and d.id in (:devices)""")
    suspend fun getTimezones(ids: List<Long>): List<TimezoneAgg>
}

before upgrade produced this result:

[
  {
    "device": {
      "id": 7,
      "name": "device1"
    },
    "name": "timezone",
    "timezone": 180
  },
  {
    "device": {
      "id": 6,
      "name": "device2"
    },
    "name": "timezone",
    "timezone": 120
  }
]

and after upgrade throws this exception:

Failed to instantiate ro.wstudios.r2dbc.device.TimezoneAgg using constructor fun <init>(ro.wstudios.r2dbc.device.DeviceAgg, ro.wstudios.r2dbc.device.DevicePropertyName, kotlin.Long): ro.wstudios.r2dbc.device.TimezoneAgg with arguments null,timezone,180
org.springframework.data.mapping.model.MappingInstantiationException: Failed to instantiate ro.wstudios.r2dbc.device.TimezoneAgg using constructor fun <init>(ro.wstudios.r2dbc.device.DeviceAgg, ro.wstudios.r2dbc.device.DevicePropertyName, kotlin.Long): ro.wstudios.r2dbc.device.TimezoneAgg with arguments null,timezone,180
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 10, 2021
@elefeint
Copy link

Drive-by comment: try adding a constructor to TimezoneAgg that omits device field from being auto-constructed. We just had a completely unrelated (not R2DBC) but similar issue because the underlying library was setting "magic" properties in post-construction.

@mp911de
Copy link
Member

mp911de commented Dec 13, 2021

Spring Data R2DBC generally does not support nested objects when trying to materialize these from a JOIN. Nested objects only work when using custom converters. I even wonder how this has worked before.

@mariusstaicu
Copy link
Author

I wondered also why it wasn't documented properly, however it was a very nice feature to have.

@mariusstaicu
Copy link
Author

Drive-by comment: try adding a constructor to TimezoneAgg that omits device field from being auto-constructed. We just had a completely unrelated (not R2DBC) but similar issue because the underlying library was setting "magic" properties in post-construction.

I will try, however if it is not supposed to be supported, I wouldn't go this way at all.

@schauder schauder added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 24, 2022
@schauder
Copy link
Contributor

As @mp911de mentioned. This was not intended to have worked in the first place since R2DBC does not support JOIN right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

5 participants