Skip to content
Advertisement

How to import data from one table to another – SpringBoot JPA /MySQL

I recently created a vehicle management system The system is derived from MySQL database and server side in spring I want to create another table (automatically at runtime) that will display only 2 of the columns of the existing table.

And the question is what am I doing wrong? Final goal – when adding / deleting / editing a vehicle, both tables will work in sync and without collisions I would be happy for your help

Below is the “Car” class

And CarType class which need only to create another MySQL table with the related columns (car_id and car_type)

Advertisement

Answer

  • Instead of checking and managing flow on the server-side. Just create Replicated Audit Table and making 3 Triggers on the original table like “After Insert, After Update, and After Delete Trigger at MySQL level.

read more about trigger Visit https://www.mysqltutorial.org/mysql-triggers.aspx

  • as @scaisEdge said also create a view from the table and implement that on your spring project.

car_detailed_view.sql [View]

CarDetailedView.java [View Class]

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement