spring-projects / spring-data-relational

Spring Data Relational. Home of Spring Data JDBC and Spring Data R2DBC.
https://spring.io/projects/spring-data-jdbc
Apache License 2.0
737 stars 339 forks source link

Nested @MappedCollection is not loaded correctly with UUID primary key #1780

Closed bent-lorentzen closed 2 months ago

bent-lorentzen commented 2 months ago

This problem is found in spring-data-jdbc version 3.2 It is still present in version 3.2.5.

Code example:

data class Foo( @Id val id: UUID = UUID.randomUUID(), @MappedCollection(idColumn = "foo_id") val bar: Bar, // If this is changes to Set the test run OK. )

data class Bar(
    @Id
    val id: UUID = UUID.randomUUID(),
    @MappedCollection(idColumn = "bar_id")
    val barItem: Set<BarItem>,
)

data class BarItem(
    @Id
    val id: UUID = UUID.randomUUID(),
    val description: String
)

@Autowired
lateinit var entityOperations: JdbcAggregateOperations

@Test
fun fooTest() {
    val foo = entityOperations.insert(Foo(bar = Bar(barItem = setOf(BarItem(description = "not null")))))

    val fooFromDb = entityOperations.findById(foo.id, Foo::class.java)
    val barItemFromDb = entityOperations.findById(foo.bar.barItem.first().id, BarItem::class.java)

    barItemFromDb!!.description shouldBe "not null" // This part runs ok, so item is correctly persisted
    fooFromDb!!.bar.barItem.first().description shouldBe "not null" // This part fails, barItem is an empty collection.
}

In our project all db keys are uuid. If I change all primary keys in this example with Long the test run OK. If I downgrade to version 3.1.11 the test runs OK.

mp911de commented 2 months ago

This sounds similar to #1684. Can you run your test against the most recent snapshot build?

spring-projects-issues commented 2 months ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues commented 2 months ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.