Configuring a database schema and populating it

Earlier in the book, in Chapter 2, Configuring Web Applications, we manually added a few entries to the database in the StartupRunner's run(...) method. While doing so programmatically can be a quick and easy way to get something going very quickly, in the long run, it is not really a good idea to do so, especially when you are dealing with a large amount of data. It is also good practice to separate the database preparations, changes, and other configurations from the rest of the running application code, even if it is setting up the test cases. Thankfully, Spring has provided you with the support to make this task fairly easy and straightforward.

We will continue with the state of the application as we left it in the previous recipe. Spring provides us with a couple of ways to define how both the structure and data should be populated in the database. The first way relies on using Hibernate to automatically create the table structure by inferring it from our defined @Entity objects and using the import.sql file to populate the data. The second approach is to use the plain old Spring JDBC capability, which relies on using the schema.sql file that contains the database table definition and a corresponding data.sql file that contains the data.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.188.157