- Fork this repo.
- Clone your fork to your local machine.
- Solve the challenges.
- Create a clean Spring Boot application.
- Upon completion, add your solution to git.
- Then commit to git and push to your repo on GitHub.
- Make a pull request and paste the pull request link in the submission field in the Student Portal.
You’ve now learned how to:
- Model relationships using JPA annotations
- Model inheritance in database tables
- Use embedded objects inside entities
- Control data loading with fetch types
In this lab, you’ll apply these concepts by modeling several systems with different relationship types.
By the end of this lab, you should be able to:
- Design JPA entities using One-to-One, One-to-Many, Many-to-Many mappings
- Create embedded objects inside entities
- Map inheritance using JPA
- Manage Lazy and Eager fetching
- Apply JPA best practices for clean and maintainable code
You'll work on three different modules:
Model the contact system for a PR company.
Entities to Create:
ContactName
Requirements:
- Create a
Nameembeddable object with the following fields:salutation(e.g., Mr., Mrs., Dr.)firstNamemiddleNamelastName
- Embed the
Nameobject inside theContactentity. Contactmust have:id(auto-generated)companytitlename(embeddedName)
Model a system for a Nurse Association with Divisions and Members.
Entities to Create:
AssociationDivisionMember
Requirements:
-
An
Associationmust have:id(auto-generated)name(e.g., "Nurse Association of Spain")- A list of divisions.
-
A
Divisionmust have:id(auto-generated)namedistrict- A president.
- A list of members.
-
A
Membermust have:id(auto-generated)namestatus(enum: ACTIVE, LAPSED)renewalDate(LocalDate)
Important:
- Use
@Enumerated(EnumType.STRING)for thestatus. - Set fetch type as appropriate for collections.
- Create and save one Association that contains 7 Divisions, each with at least one Member.
Model an event management application.
Entities to Create:
EventConferenceExhibitionGuestSpeaker
Requirements:
-
Eventmust have:id(auto-generated)titledate(LocalDate)duration(Integer)location- A list of guests.
-
Guestmust have:id(auto-generated)namestatus(enum: ATTENDING, NOT_ATTENDING, NO_RESPONSE)
-
Conferencemust have:- A list of speakers.
-
Speakermust have:id(auto-generated)namepresentationDuration(Integer)
Important:
- Use
@Inheritance(strategy = InheritanceType.X)where appropriate. - Create necessary associations without explicitly being told the type. Think about how the tables should be connected.
- Use
@Enumerated(EnumType.STRING)for enums. - Model join tables where necessary.
(Recommended if you finish early!)
Model a simple task management system with the following specifications:
Entities to Create:
TaskBillableTaskInternalTask
Requirements:
-
A
Taskmust have:id(auto-generated)titledueDate(LocalDate)completed(boolean)
-
BillableTaskmust have:hourlyRate(BigDecimal)
-
InternalTaskhas no additional fields.
Important:
- Use
@Inheritance(strategy = InheritanceType.X)as needed.
- Define all entities with appropriate JPA annotations.
- Use
@Inheritance(strategy = InheritanceType.X)where needed. - Create the necessary repository interfaces for each entity.
- Use CommandLineRunner or a @Configuration class to create and save at least 3 sample entries per entity (or logical group).
- (Optional) Add simple query methods in repositories:
- Find divisions by district
- Find guests by status
Answer these in a file bonus-questions.txt inside your repo:
- List 3 tasks that can be performed with native SQL but are hard or impossible with JPQL.
- Explain why you might prefer using native SQL over JPQL in real-world projects.
Can I use CommandLineRunner to insert sample data?
Yes! It's recommended. You can also use REST controllers later if you prefer.
Should I use DTOs and services already?
Not required yet! Focus on modeling the entities and relationships.
How do I choose FetchType.LAZY or FetchType.EAGER?
- Use LAZY for collections unless you absolutely need the data immediately.
- Use EAGER carefully for simple single relationships.
🎯 Take your time, model your relationships thoughtfully, and build a solid base for future more complex applications!
✅ Nothing is given away (no OneToOne, OneToMany hints).
✅ Association is correctly included.
✅ Student must figure out the relationships themselves.
✅ Ready to copy-paste into GitHub or classroom platforms.
