Labs

  1. Create a class RelationshipCRUDClient in the com.example.jpavideostore.client package.

  2. Write a method public void addNewActorToFilm() that

  3. Creates a new Actor object with firstName and lastName values.
  4. Sets up a relationship such that the new Actor is in the movie LADYBUGS ARMAGEDDON (film with id 507).
  5. Persists the actor to the database.

  6. Create a main method in your RelationshipCRUDClient class. Have it invoke your addNewActorToFilm method.

  7. Check your SQL database to see if the new Actor was created, and that the appropriate relationship was added to the film_actor table.

  8. Write a method public void newCustomerAndAddress() that

  9. Creates a new Address with the following values set:
    • street
    • city
    • state
    • phone
  10. Creates a new Customer object with the following values set:
    • firstName
    • lastName
    • store (use the store with id 1)
    • email
    • createdAt (use new Date() to get todays date)
    • address (use the address you just created)
  11. Add a CascadeType.Persist to the @OneToOne annotation on the Customer's address field.
  12. Persists the Customer to the database.

  13. Comment out the call to addNewActorToFilm and invoke your newCustomerAndAddress method in RelationshipCRUDClient's main method.

  14. Check your SQL database to see if the new Address and Customer objects were created.

Prev -- Up