I was trying to use a spring boot initializer using intelij IDEA. I used dependancies like spring-web, spring data-JPA and H2 sql. Afrter implementing the necessary steps I was able to get the H2 console running and sucessfull database connection. But, the entity I created is not apearing in the database. [h2_console after running my java application]
I tried the following steps:
create my project by adding the dependancies I mentioned above.(The main application class)
```java package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Demo5Application { public static void main(String[] args) { SpringApplication.run(Demo5Application.class, args); } } ```
create the packege for defining my entity nemed "entity".[package_entity]
Then I created a class called "Book" to define my entity properties.[entity_properties]
```java package com.example.demo.entity; import javax.persistence.*; @Entity public class Book { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; private String name; private String category; private String sector; private String type; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getCategory() { return category; } public void setCategory(String category) { this.category = category; } public String getSector() { return sector; } public void setSector(String sector) { this.sector = sector; } public String getType() { return type; } public void setType(String type) { this.type = type; } } ```
provide them their getters and setters.(as shown above)
Use the proper annotaions for each parts.(@Entity, @ID, @GeneratedValue) 6- Then, I go to the application.properties to add more information about my H2 database.[application_properties]
spring.datasource.driver-class-name=org.h2.Driver spring.datasource.url=jdbc:h2:mem:sarita spring.datasource.username=SA spring.datasource.password= spring.h2.console.enabled=true spring.h2.console.path=/h2 spring.jpa.show-sql=true spring.jpa.hibernate.ddl-auto=create
After all those steps I run my application. The connection is showing my success.[successfull_h2_db_connection]
But, when I hit connect it will get inside. However, there is no table created inside as I expected!!![no_table_created]
In all the tutorials I saw they were able to see this table in their H2 console. What mistake did I made for my failure?
Thanks!!!