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.
- Team up in pairs of 2
- Find another pair to team up with
- Create a team of 4 people in Moodle
- ONE team member should clone the following GitHub repository:
git clone -b code-lab-3 https://github.com/tysker/3sem-codelab-exercises.git. - Delete the
.gitfolder in the project folder. - Create a new GitHub repository and push the project to the new repository.
- 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:
developand Protect themainbranch and thedevelopbranch 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)
- Each member should create a database in your docker environment with postgres called
university. - Set up the HibernateConfig file to connect to the database.
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?
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.
- Implement the GenericDAO interface for the Course class.
- Implement the GenericDAO interface for the Teacher class.
- Implement the GenericDAO interface for the Student class.
- 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.
- Create a branch off the
developbranch for each task - Work on the tasks in pairs
- Create a Pull Request to merge the task branch into the
developbranch - Assign the Pull Request to the other pair for review
- Review the Pull Request
- Provide feedback
- Merge the Pull Request and delete the branch
- Identify the next tasks
- Repeat steps 5-8 for the next tasks

