O'Reilly logo

Hands-On High Performance with Spring 5 by Dinesh Radadiya, Prashant Goswami, Pritesh Shah, Subhash Shah, Chintan Mehta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The JPA way of initial data loading

Spring Data JPA provides a way to execute database manipulation commands on the application startup. As the schema will be generated in the database from the JPA entity configuration and ddl-auto property value, we have to take care to insert the account records in the accounts table only. The following are the steps to accomplish this:

  1. Add the following property to the application.properties file:
spring.datasource.initialization-mode=always
  1. Create a data.sql file with INSERT queries in the src/main/resources folder of the project:
INSERT INTO accounts (ACCT_NAME) VALUES  ('Savings'),  ('Current'),  ('Fixed Deposit'),  ('Recurring Deposit'),  ('Loan');

That's it! When we start the application, Spring will ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required