JPA part II - CodeLab Exercise
This CodeLab exercise is designed to help you practice the concepts you have learned on the first day of JPA part 2. 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. Set up the development environment (one per team of 2 x 2)
- ONE team member should copy-paste the following link into a bash/cmd terminal:
git clone -b code-lab-3 https://github.com/tysker/3sem-codelab-exercises.git
. (This will clone the repository on thecode-lab-3
branch) - Delete the
.git
folder in the project folder. - Create a new GitHub repository and push the project to the new repository.
- Make everybody else collaborators on the repo.
- Here are a link to the Hibernate Config file and the pom.xml dependencies if you need them.
- 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
university
. - Set up the HibernateConfig file to connect to the database.
4. The assignment
You are going to create a simple application for a university. The application should be able to manage students, courses and teachers. This time around we are going to add relationships between the entities. The relationships can be seen in the diagram above. Most of the code is already written for you. You need to implement the missing parts. Make sure to use the correct annotations for the relationships and try to understand how the relationships work.
Remember to write integration tests for the DAO classes.
Ask yourself the following questions before you start implementing the relationships:
- What are the relationship between the entities?
- Which one should be the owning side of the relationship and what does that mean?
- Should the relationship be unidirectional or bidirectional?
- What cascade type should be used or should we use them at all? What are the implications?
- Should we use fetch type eager or lazy and why?
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 an Enum for the Course class as shown in the diagram and add the correct annotations to the Course class.
- Add the correct annotations to the Teacher class as shown in the diagram.
- Add the correct annotations to the Student class as shown in the diagram.
- Implement the GenericDAO interface for the CourseDAO class and implement the methods.
- Implement the GenericDAO interface for the TeacherDAO class and implement the methods.
- Implement the GenericDAO interface for the StudentDAO class and implement the methods.
- Add the relations between the entities as shown in the diagram.
- a) student can attend many courses
- b) a course can have many students
- c) course can have only one teacher
- d) a teacher can teach many courses
- Look at the DTO diagram below and implement the methods in the DAO classes to get the data as shown in the diagram.
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