spring-data-relational icon indicating copy to clipboard operation
spring-data-relational copied to clipboard

Nested @MappedCollection is not loaded correctly with UUID primary key

Open bent-lorentzen opened this issue 1 year ago • 1 comments
trafficstars

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<Bar> 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.

bent-lorentzen avatar Apr 26 '24 11:04 bent-lorentzen

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

mp911de avatar Apr 26 '24 12:04 mp911de

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 avatar May 03 '24 12:05 spring-projects-issues

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.

spring-projects-issues avatar May 10 '24 12:05 spring-projects-issues