I have a small favor to ask you. Do help me keep my Youtube Channel czetsuyatech going by sharing my videos and subscribing to my channel so that it can reach and help more viewers.
Help me create more FREE online courses and learning materials for programmers and remote workers by becoming my Patron.
There are times when we want to use a SQL script to generate the schema and populate the database. Personally, I use the code which we previously discussed as it triggers notifications which you might have set in entity’s create or update method. But sometimes, you might already have a large chunk of sample data from excel exported from another system that you need to do some processing and that is when this method is useful.
Going back to the project we first need to change the value of spring.jpa.hibernate.ddl-auto to validate.
[open application.properties]
This instructs Spring not to auto-generate the database schema from the entity classes, rather use the schemal.sql and data.sql files located in src/main/resources folder.
Let’s take a look at the SQL files.
[open schema.sql]
Here we defined the tables which mapped to the entity classes.
[open data.sql]
Needless to say, this is where we insert records.
Now let’s run the application. As expected the tables are created and 1 row of a category is inserted.
I have a small favor to ask you. Do help me keep my Youtube Channel czetsuyatech going by sharing my videos and subscribing to my channel so that it can reach and help more viewers.
Help me create more FREE online courses and learning materials for programmers and remote workers by becoming my Patron.
Post a Comment