Skip to content

A complete study project on Java Persistence API (JPA) using PostgreSQL. Features a fully generic DAO layer, unit testing with JUnit 5, and entity persistence with annotations and dynamic JPQL.

Notifications You must be signed in to change notification settings

AsrielDreemurrGM/Study_Of_Java_JPA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Study of Java JPA

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.

🚀 Key Features

  • ✅ JPA-based persistence with PostgreSQL;
  • ✅ Generic DAO structure for all entities using GenericDAO<T> and IGenericDAO<T>;
  • ✅ Domain entities: Course, Enrollment, and Product 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.

🗂️ Project Structure

  • 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.

🧪 Testing Approach

  • ✅ 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 use ChronoUnit.MILLIS for accuracy;
  • ✅ All tests run using a PostgreSQL database configured via persistence.xml.

📋 Technologies Used

  • Java 17+;
  • JPA 2.2 (Jakarta Persistence);
  • PostgreSQL 14+;
  • Hibernate 5.6.2.Final;
  • JUnit 5 for testing;
  • pgAdmin 4;
  • Spring Tools Suite 4.

📑 Learning Objectives

  • 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.

⚙️ Configuration

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.

About

A complete study project on Java Persistence API (JPA) using PostgreSQL. Features a fully generic DAO layer, unit testing with JUnit 5, and entity persistence with annotations and dynamic JPQL.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages