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 and collaboration using Github.
Exercise Overview
Instructions
1. Team up (2 x 2)
- Team up in pairs of 2
- Find another pair to team up with
- Create a team of 4 people in Moodle
2. Setup the development environment (one per team of 2 x 2)
- One team member should create a new github repository and make everybody else collaborators on the repo.
- Then create a new maven project with a Hibernate Config file and the appropriate pom.xml dependencies for using with JPA.
- Create a new branch:
develop
and Protect themain
branch and thedevelop
branch from pushing directly to it. Only allow Pull Requests to merge into these branches. - Every team member should clone the new repository to their local machine
- Checkout the develop branch (each member)
3. Connecting to the database
- Each member should create a database in your docker environment with postgres called
jpademo
. - Set up the HibernateConfig file to connect to the database.
- 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 branch off the
develop
branch for each task - Work on the tasks in pairs
7. Pull request
- Create a Pull Request to merge the task branch into the
develop
branch - Assign the Pull Request to the other pair for review
8. Review (description of how to conduct code reviews using pull requests)
- Review the Pull Request
- Provide feedback
- Merge the Pull Request and delete the branch
9. Repeat
- Identify the next tasks
- Repeat steps 5-8 for the next tasks