diff --git a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/dataloading/ApplicationDataLoading.java b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/dataloading/ApplicationDataLoading.java index 619f0e0411..40742d303e 100644 --- a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/dataloading/ApplicationDataLoading.java +++ b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/dataloading/ApplicationDataLoading.java @@ -2,19 +2,15 @@ package com.baeldung.dataloading; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.ApplicationContext; import org.springframework.core.env.AbstractEnvironment; -import com.baeldung.boot.Application; - @SpringBootApplication(scanBasePackages = { "com.baeldung.dataloading" }) public class ApplicationDataLoading { - private static ApplicationContext applicationContext; - public static void main(String[] args) { - System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, "datasource"); + public static void main(String[] args) { + System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, "datasource"); - applicationContext = SpringApplication.run(Application.class, args); - } + SpringApplication.run(ApplicationDataLoading.class, args); + } } diff --git a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/dataloading/model/Country.java b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/dataloading/model/Country.java new file mode 100644 index 0000000000..692d48caf0 --- /dev/null +++ b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/dataloading/model/Country.java @@ -0,0 +1,36 @@ +package com.baeldung.dataloading.model; + +import static javax.persistence.GenerationType.IDENTITY; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class Country { + + @Id + @GeneratedValue(strategy = IDENTITY) + private Integer id; + + @Column(nullable = false) + private String name; + + 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; + } + +} diff --git a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/dataloading/model/User.java b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/dataloading/model/User.java deleted file mode 100644 index e0927f3646..0000000000 --- a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/dataloading/model/User.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.baeldung.dataloading.model; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Table; - -@Entity -@Table(name = "users") -public class User { - - @Id - @GeneratedValue - private Integer id; - private String name; - private Integer status; - - public User() { - } - - public User(String name, Integer status) { - this.name = name; - this.status = status; - } - - 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 Integer getStatus() { - return status; - } - - public void setStatus(Integer status) { - this.status = status; - } -} diff --git a/persistence-modules/spring-boot-persistence/src/main/resources/application-datasource.properties b/persistence-modules/spring-boot-persistence/src/main/resources/application-datasource.properties index 11f409719f..98cf2ba965 100644 --- a/persistence-modules/spring-boot-persistence/src/main/resources/application-datasource.properties +++ b/persistence-modules/spring-boot-persistence/src/main/resources/application-datasource.properties @@ -2,10 +2,13 @@ spring.datasource.driver-class-name=org.h2.Driver spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1 spring.datasource.username=sa spring.datasource.password= -spring.jpa.hibernate.ddl-auto=none + +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect +spring.jpa.hibernate.ddl-auto=create +spring.jpa.defer-datasource-initialization=true + # Enabling H2 Console spring.h2.console.enabled=true -# Uppercase Table Names -spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl -hibernate.globally_quoted_identifiers=true -spring.jpa.database-platform=org.hibernate.dialect.H2Dialect + +# By default enabled for Embedded Databases +#spring.sql.init.mode=always \ No newline at end of file