Este README também está disponível em Português Brasileiro.
This project demonstrates how to implement a clean, test-driven backend architecture using the Java Persistence API (JPA) with PostgreSQL and JUnit 5. It focuses on reusability and separation of concerns through a Generic DAO pattern and fully annotated entity classes.
- ✅ JPA-based persistence with PostgreSQL;
- ✅ Generic DAO structure for all entities using
GenericDAO<T>
andIGenericDAO<T>
; - ✅ Domain entities:
Course
,Enrollment
, andProduct
with validation constraints and sequence generation; - ✅ JPQL-based dynamic queries for search and update operations;
- ✅ JUnit 5 test classes covering full CRUD functionality for all DAOs;
- ✅ Automatic ID management using
@SequenceGenerator
and@GeneratedValue
; - ✅ JPA configuration via
persistence.xml
with PostgreSQL connection and Hibernate properties; - ✅ Full Javadoc coverage added for all entities, DAOs, generic classes, and test suites, including
@link
references for better navigation; - ✅ Comprehensive relationship mappings including One-To-Many, Many-To-Many, and One-To-One between entities;
- ✅ Achieved 100% test coverage across all project modules.
br.com.eaugusto.domain
: Contains all JPA entity classes;br.com.eaugusto.dao
: Interfaces and classes for each entity DAO;br.com.eaugusto.dao.generic
: Reusable generic DAO interface and implementation;br.com.eaugusto.dao.interfaces
: Dedicated package for DAO interfaces to organize code;src/test/java
: Unit test classes covering all DAO methods and entity operations, including relationship tests;src/main/java/META-INF/persistence.xml
: JPA configuration file.
- ✅ Built entirely with JUnit 5 using assertions and lifecycle annotations (
@BeforeEach
,@AfterEach
); - ✅ Test coverage includes insert, update, search by ID, search all, and delete operations;
- ✅ Relationship integrity tested with entity associations (One-To-Many, Many-To-Many, One-To-One);
- ✅ Time-based tests for
Instant
comparisons useChronoUnit.MILLIS
for accuracy; - ✅ All tests run using a PostgreSQL database configured via
persistence.xml
.
- Java 17+;
- JPA 2.2 (Jakarta Persistence);
- PostgreSQL 14+;
- Hibernate 5.6.2.Final;
- JUnit 5 for testing;
- pgAdmin 4;
- Spring Tools Suite 4.
- Understand how JPA annotations map Java classes to database tables;
- Implement a generic DAO architecture for entity management;
- Use JPQL for dynamic queries with entity classes;
- Apply TDD and verify data persistence using comprehensive unit tests;
- Manage complex entity relationships and cascading operations;
- Document code thoroughly with Javadocs for maintainability.
All persistence settings can be adjusted in the persistence.xml
file located in
src/main/java/META-INF/
. You can configure:
- Database URL;
- Username and password;
- Hibernate dialect and schema generation strategy;
- SQL logging options for debugging purposes.