![]() Insert into User(id, firstname, lastname, email, location_id) values(2, 'Jeffrey', 'Yuba', ' ', 2) Insert into User(id, firstname, lastname, email, location_id) values(1, 'Kindson', 'Munonye', ' ', 1) Insert into Location(id, name) values(3, 'Califonia, USA') Insert into Location(id, name) values(2, 'Owerri, Nigeria') Step 2: Open the file and add the following code insert into Location(id, name) values(1, 'Budapest, Hungary') Step 1: Create a file inside the src/main/resources folder. We would write a script to insert some initial data into the database. Part 5 – Database Initialization (data.sql) ![]() Step 3: Run the the application and access the H2 Console Step 2: Add the following code in the application.properties file Step 1: Open the application.properties file. Now we configure the H2 database following the steps below: H2 Database is an in-memory database that is normally used during development. Similarly, the Post entity does this by creating a column called user_id In the first case, the User entity does this by creating a column called location_id in the User table. ![]() When you use these annotation, the entity decides to handle the relationship. Step 2: Annotate the User field of the Post entity with annotation Step 1: Annotate the Location field of the User entity with annotation. We would now configure Many-to-one relationship between the User and the Location entities. Similarly, we do the same between the Post and User entities. Step 5: Finally, create the RestControllers in the controllers package Step 4: Create the services in the Services package Step 3: Also create all the repositories in the repositories package Step 2: Create three classes corresponding to Post, User and Location. Step 1: Create a Spring application (you should be able to do this by now). In this part, we would set up a Spring Boot Starter application. This is illustrated in the figure below Relationship Diagram How they relate is that: Location contains users and User has posts. In this comprehensive tutorial, we’ll build an application made up of three entities: Location, User and Post.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |