I have the following files in my spring boot project. And I would like to use the tables and be able to consume that data with my restful api. I have the create-drop but that creates and deletes every time I run the application and the tables are empty because I don't insert anything during the create-drop. But I already have data in the tables and I can't get it, the get with postman brings me a 200 but it's empty. My mistake is in the logic of the properties.
# Datasource configurations.
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=create
# Datasource configurations.
spring.datasource.url=jdbc:mariadb://localhost:3306/aulas_db
spring.datasource.username=root
spring.datasource.password=1234
spring.datasource.driverclassName=org.mariadb.jdbc.Driver
spring.jpa.hibernate.ddl-auto=create-drop
spring.main.banner-mode=off
server.servlet.context-path = /api
server.port = 8090
# spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
# Logger configurations.
logging.level.com.capgemini.serviciosya = DEBUG
logging.level.org.springframework.data = DEBUG
logging.level.org.hibernate.type = TRACE
# Hibernate
hibernate.dialect = org.hibernate.dialect.MariaDB53Dialect
hibernate.show_sql = true
hibernate.hbm2ddl.auto = validate
entitymanager.packagesToScan = ar.edu.unaj.reports.entity
spring.profiles.active=dev
You can use
update
which allows you to update the schema you are working on.The property
spring.jpa.hibernate.ddl-auto
is specific to Spring Data JPA and is its way of specifying a value that will eventually be passed to Hibernate under the property it knows about,hibernate.hbm2ddl.auto
.create
The ,create-drop
,validate
and valuesupdate
basically influence how the database schema will be handled at startup.So the list of possible options are:
validate
: validate the schema, does not make changes to the database.update
: update the schema.create
: create the schema, destroying the previous data.create-drop
: removes the schema whenSessionFactory
it is explicitly closed, usually when the application is stopped.