22:source-highlighter: highlight.js
33Rashidi Zin <rashidi @zin.my >
441.0, July 13, 2025
5- :toc:
65:nofooter:
76:icons: font
87:url-quickref: https://github.com/rashidi/spring-boot-tutorials/tree/master/data-rest-composite-id
@@ -21,7 +20,7 @@ This example demonstrates how to implement and expose entities with composite ID
2120
2221== Entity Classes
2322
24- In this example, we have two entity classes: `Book`[$ {source-main}/book/Book.java] and `Author`[$ {source-main}/book/Author.java].
23+ In this example, we have two entity classes: link: {source-main}/book/Book.java[`Book` ] and link: {source-main}/book/Author.java[`Author` ].
2524Both use composite IDs implemented as embedded classes.
2625
2726=== Book Entity
@@ -233,13 +232,13 @@ void create() {
233232 .post().uri("/books")
234233 .content("""
235234 {
236- "isbn": "9781509827829 ",
235+ "isbn": "9781402745777 ",
237236 "title": "The Jungle Book",
238237 "author": "http://localhost/authors/100"
239238 }
240239 """)
241240 .assertThat().headers()
242- .extracting(LOCATION).asString().isEqualTo("http://localhost/books/9781509827829 ");
241+ .extracting(LOCATION).asString().isEqualTo("http://localhost/books/9781402745777 ");
243242}
244243----
245244
@@ -251,8 +250,8 @@ This test creates a Book with an ISBN, title, and author reference, then verifie
251250----
252251@Test
253252@Sql(statements = {
254- "INSERT INTO author (id, first_name, last_name) VALUES (100 , 'Rudyard', 'Kipling')",
255- "INSERT INTO book (prefix, registration_group, registrant, publication, check_digit, author_id, title) VALUES (978, 1, 509, 82782, 9, 100 , 'The Jungle Book')"
253+ "INSERT INTO author (id, first_name, last_name) VALUES (200 , 'Rudyard', 'Kipling')",
254+ "INSERT INTO book (prefix, registration_group, registrant, publication, check_digit, author_id, title) VALUES (978, 1, 509, 82782, 9, 200 , 'The Jungle Book')"
256255})
257256@DisplayName("Given a book is available When I request by its ISBN Then its information should be returned")
258257void get() {
0 commit comments