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

  1. 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
  1. In Product, add a field named id with type int. Now, set this as the Id for the store entity. Finally, specify the Id is a generated value and uses the identity strategy.

  2. In Order, add a field named id with type int. 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 is ORDER_SEQ.

  3. In Store, add a field named name with type String, and a field named owner with type String. Set both of these fields as Ids. Now, specify the entity uses StorePK as an Id class.

Don't forget to generate getters/setters for added fields.

Verification

  1. Start the training application and go to the app home page

  2. Click on the link 'Exercise One Get Product'. Verify the resulting JSON contains:

    "href" : "http://localhost:8080/products/1"

  3. Click on the link 'Exercise One Get Order'. Verify the resulting JSON contains:

    "href" : "http://localhost:8080/orders/1"

  4. Click on the link 'Exercise One Get Store'. Verify the resulting JSON contains:

    "name":"Joe's Sports Store","owner":"Joe"