This repository contains a command-line interface (CLI) application built with Spring Boot, Spring Data JPA and Hibernate. It demonstrates full CRUD (Create, Read, Update, Delete) operations on a MySQL database for managing companies, departments, tasks and employee information.
- Comprehensive CRUD Operations: Perform Create, Read, Update and Delete operations for all entities.
- Relational Data Model: Manages relationships between entities (Company, Department, Task, Employee).
- Interactive CLI: A user-friendly command-line menu to interact with the application.
- JPA & Hibernate: Utilizes Java Persistence API (JPA) with Hibernate as the persistence provider for object-relational mapping.
- Advanced SQL Schema: Includes a detailed SQL script with table definitions, constraints, triggers, stored procedures and scheduled events for database setup.
- Data Validation: Implements input validation both in the application logic and at the database level with constraints and triggers.
The application uses a relational schema with four main tables: company, department, task and information.
- A Companyhas a one-to-many relationship withDepartment.
- A Departmenthas a one-to-many relationship withTaskandInformation(employees).
- A Taskcan be assigned to multiple employees (one-to-many relationship withInformation).
The Application.sql file contains the complete schema definition including:
- Table creation with constraints.
- Database triggers for data formatting and integrity (e.g., capitalizing company names).
- Stored procedures for maintenance tasks (e.g., resetting auto-increment values).
- Scheduled events for periodic data updates (e.g., updating employee ages).
- Java 24
- Spring Boot
- Spring Data JPA
- Hibernate
- MySQL
- Maven
- Java JDK 24 or later
- Maven
- MySQL Server
- 
Clone the repository: git clone https://github.com/panoschron97/Spring_Data_JPA_Hibernate_MySQL_Crud_App.git cd Spring_Data_JPA_Hibernate_MySQL_Crud_App
- 
Database Setup: - Ensure your MySQL server is running.
- Execute the Application.sqlscript located in the root directory. This will create theapplicationdatabase, tables, triggers and stored procedures. You can use a MySQL client like MySQL Workbench or the command line:mysql -u your_mysql_username -p < Application.sql
 
- 
Configure Database Connection: - Open the crud/src/main/resources/application.propertiesfile.
- Update the following properties to match your MySQL configuration:
spring.datasource.url=jdbc:mysql://localhost:3306/application spring.datasource.username=your_mysql_username spring.datasource.password=your_mysql_password 
 
- Open the 
- 
Build and Run the Application: - Navigate to the cruddirectory:cd crud
- Build the project using Maven:
mvn clean install 
- Run the application:
mvn spring-boot:run 
 
- Navigate to the 
Once the application is running, it will display a menu of options in the console. Enter the number corresponding to the action you want to perform.
Menu Options:
- Add a new company.
- Add a new company along with a department.
- Add a new department to an existing company.
- Add a new task to a department.
- Add a new employee.
- View all companies and their departments.
- View all companies.
- View all departments.
- View all tasks.
- View all employees.
- View a specific department and its associated company.
- View a specific company and its list of departments.
- Update a company's details.
- Delete a company.
- Update a department's details.
- Delete a department.
- Update a task's details.
- Delete a task.
- Update an employee's details (e.g., assign to a new task).
- Delete an employee.
- View a specific task and its associated department.
- View a specific employee with their department and task details.
- Exit the application.