Skip to content

Latest commit

 

History

History
52 lines (52 loc) · 2.47 KB

File metadata and controls

52 lines (52 loc) · 2.47 KB

JPA Multi-Database Testing Project

Este README também está disponível em Português.

This project explores how to configure and interact with multiple databases using JPA. It includes PostgreSQL and MySQL setups with a flexible DAO structure and test coverage across three persistence units.

📁 Project Overview

The project began with support for two PostgreSQL databases and later extended to include a third MySQL database. It demonstrates how to:

  • Structure JPA DAOs to support multiple persistence units;
  • Perform CRUD operations across PostgreSQL and MySQL simultaneously;
  • Use environment variables for database credentials;
  • Write unit tests for each database configuration.

🧪 Technologies Used

  • Java 21
  • JPA
  • JUnit 5
  • PostgreSQL
  • MySQL
  • Spring Tools Suite 4 (STS4)

⚙️ Setup Instructions

  1. Make sure you have Java 17+ installed (Project tested on Java 21);
  2. Install both PostgreSQL and MySQL databases locally or configure remote instances;
  3. Create and configure the following environment variables:
    • DB_URL – JDBC URL for your default database (used by DB1);
    • DB_USERNAME – Your DB username;
    • DB_PASSWORD – Your DB password.
  4. Edit persistence.xml in the META-INF folder if necessary to adjust connection URLs and driver properties;
  5. Run the test classes to validate integration across databases.

📜 Commit Highlights

  • Project Setup – Initialized the project based on a previous JDBC migration structure;
  • Two DB Support – Added DAOs and tests for PostgreSQL using two persistence units;
  • Three DB Support – Integrated MySQL as a third database with new DAO and test class;
  • Full Documentation – Added Javadocs to all entity, DAO, and test classes with internal links for easy navigation.

📝 Notes

  • Make sure to include the required JAR files for MySQL/PostgreSQL in your classpath;
  • All required JAR files are located in the project-files folder;