Mergetable is a Spring Boot project that demonstrates entity merging using JPA event listeners. Instead of using database triggers, it listens for Hibernate insert events on the User and Address tables and updates a third table, OneForAll, which contains combined fields from both entities.
- JPA Event Listeners: Automatically updates
OneForAllwhenUserorAddressis created. - No Database Triggers: Ensures data consistency at the application level.
- Simple API: Supports only create operations for testing merging.
- Backend: Java (Spring Boot)
- Database: MySQL (or any relational database)
- ORM: Hibernate with JPA event listeners
- User Table → Stores user-related data.
- Address Table → Stores address-related data.
- OneForAll Table → Stores combined fields from
UserandAddress. - JPA Event Listeners detect insert operations in
UserandAddressand automatically populateOneForAll.
- Java 17+
- MySQL database
- Maven
- Clone the repository:
git clone https://github.com/aditya9389/mergetable.git cd mergetable - Configure the database in
application.properties:spring.datasource.url=jdbc:mysql://localhost:3306/mergetable spring.datasource.username=root spring.datasource.password=root spring.jpa.hibernate.ddl-auto=update
- Run the application:
mvn spring-boot:run
- Endpoint:
POST /create - Description: Inserts a new user and address, triggering the
OneForAlltable update. - Request Body Example:
{ "user": { "name": "John Doe", "email": "[email protected]" }, "address": { "street": "123 Main St", "city": "New York" } }
- Add update and delete event handling.
- Implement API for fetching merged data.
- Expand to support more entity relationships.
For any questions, feel free to reach out via email or GitHub issues.