1

So, i have class, annotated with entity and when i start Spring boot application i expect Hibernate to create Table in h2, but i see nothing h2 Spring application properties got only spring.h2.console.enabled=true

my class looks like

@Entity

public class Author {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

private String firstName;
private String lastName;


private Set<Book> books = new HashSet<>();

public Author() {
}

please Halp

evgenij
  • 11
  • 5
  • Check is this helps? https://stackoverflow.com/questions/26881739/unable-to-get-spring-boot-to-automatically-create-database-schema?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Prav May 29 '18 at 21:39
  • Possible duplicate of [How to create database schema in hibernate first time and further update it in case of schema modification?](https://stackoverflow.com/questions/8815037/how-to-create-database-schema-in-hibernate-first-time-and-further-update-it-in-c) – Robert Moskal May 29 '18 at 21:43

1 Answers1

1

JPA has features for DDL generation, and these can be set up to run on startup against the database. This is controlled through two external properties:

spring.jpa.generate-ddl (boolean) switches the feature on and off and is vendor independent. spring.jpa.hibernate.ddl-auto (enum) is a Hibernate feature that controls the behavior in a more fine-grained way.

Your properties file should look something like this:

spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect