JPA part I - CodeLab Exercise
This CodeLab exercise is designed to help you practice the concepts you have learned in the JPA 1 module on day 1. You will be working on a series of tasks that involve Java Persistence API, with Entities and DAOs. We will also practice pair programming if possible.
Exercise Overview
Instructions
1. Team up with a buddy
- Help each other working together in pairs
2. Setup the development environment (everyone)
- Create a new Maven project getting ready for JPA with Hibernate. Use the JPA setup in IntelliJ guide to help you - or use your own starter project / template.
- Make sure your
.gitignore
file is set up correctly and then initialize a new Git repository in your project folder. Add and commit your files. - Create a new repository on GitHub, link them up, and push your project to the repository.
3. Connecting to the database (warm up)
- Each person should create a database in your docker environment with Postgres called
jpademo
. - Set up the Hibernate to connect to the database. Use the
config.properties
file to store the database name - and credentials. - Create a new Entity class called
Person
with the following fields:- id (int)
- name (String)
- age (int)
-
Create a new DAO class called
PersonDAO
with the following methods:createPerson(Person person)
- Create a new Main class and test that you can add a new person to your database.
4. The assignment
You are going to create a new student management system. We need to be able to persist data about students and their courses. We need to have information about each student such as their name, phone number, email, address, status, date of birth, date of enrollment and whatever you think is relevant. We also need to have information about the courses they are taking such as the name of the course, the teacher, the semester, the classroom, the time of the course and whatever you think is relevant. Since we have not yet learned how to create relationships/references between entities, you can choose to just store the id of the courses in the student entity for now (we will learn how to do it the right way in JPA week 2).
5. Identify tasks, break them down and assign to pair programmers as Issues in Github
The following tasks are suggestions for the first round of tasks. You can add more tasks as you go along.
- Create new student
- Create new course
- Update student information
- Update course information
- Delete student
- Delete course
- List all students
- List all courses
- List all courses for a specific student
- List all students for a specific course (use streams and filters for this one)
- Come up with more tasks as you go along …
6. Start working on the tasks (round 1)
- Create a feature branch off the
main
branch for each task - Work on the tasks in pairs
7. Merge your feature branch in to the main
branch
- After completing the task, add, commit, and push your changes to the repository
- Switch to the main branch - and merge the latest changes from the feature branch.
8. Repeat
- Identify the next tasks
- Repeat steps 6-7 for the next tasks