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.
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.
- Java 21
- JPA
- JUnit 5
- PostgreSQL
- MySQL
- Spring Tools Suite 4 (STS4)
- Make sure you have Java 17+ installed (Project tested on Java 21);
- Install both PostgreSQL and MySQL databases locally or configure remote instances;
- 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.
- Edit
persistence.xmlin theMETA-INFfolder if necessary to adjust connection URLs and driver properties; - Run the test classes to validate integration across databases.
- 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.
- Make sure to include the required JAR files for MySQL/PostgreSQL in your classpath;
- All required JAR files are located in the
project-filesfolder;