Same Customer/Order/OrderItem domain modelled with Hibernate/Spring Data JPA and Spring Data JDBC side by side, both running through a shared StatementLoggingDataSource so SQL-statement counts are directly comparable. 11 tests, 11 captured transcripts, 6 doc chapters. Companion repo for the ankurm.com article on when to drop the ORM.
12 lines
591 B
Plaintext
12 lines
591 B
Plaintext
Scenario: save items in the order [SKU-Z, SKU-A, SKU-M] (deliberately not
|
|
alphabetical), reload, and read the list back.
|
|
|
|
reloaded order: [SKU-Z, SKU-A, SKU-M]
|
|
|
|
@MappedCollection(idColumn = "order_id", keyColumn = "order_key") is what makes
|
|
this deterministic. Without keyColumn, Spring Data JDBC still stores a List
|
|
correctly, but the reload order is whatever the database happens to return —
|
|
usually insertion order on a fresh H2 table, but that is an implementation
|
|
detail, not a guarantee, and it is the kind of thing that breaks quietly on a
|
|
different database or after a compaction.
|