Exercise 01: Entities and Primary Key Mappings - jkneal/spring-angular-train GitHub Wiki
Goals
Set up a few basic entities which map up to existing database tables and practice with a few different varieties of ID column mappings.
Instructions
- Within src/main/java, create the following entities that map to the specified table.
| Class | Table |
|---|---|
| edu.train.store.Store | STORE_T |
| edu.train.product.Product | PRODUCT_T |
| edu.train.order.Order | ORDER_T |
-
In
Product, add a field namedidwith typeint. Now, set this as the Id for the store entity. Finally, specify the Id is a generated value and uses the identity strategy. -
In
Order, add a field namedidwith typeint. Now, set this as the Id for the store entity. Finally, specify the Id is a generated value and uses the sequence strategy. The sequence name isORDER_SEQ. -
In
Store, add a field namednamewith typeString, and a field namedownerwith typeString. Set both of these fields as Ids. Now, specify the entity usesStorePKas an Id class.
Don't forget to generate getters/setters for added fields.
Verification
-
Start the training application and go to the app home page
-
Click on the link 'Exercise One Get Product'. Verify the resulting JSON contains:
"href" : "http://localhost:8080/products/1"
-
Click on the link 'Exercise One Get Order'. Verify the resulting JSON contains:
"href" : "http://localhost:8080/orders/1"
-
Click on the link 'Exercise One Get Store'. Verify the resulting JSON contains:
"name":"Joe's Sports Store","owner":"Joe"