I’m using MySql database and springboot, when i run the app, the table does not created in the database! if i remove the DB and run the app, it detect that there is no DB (it means, its connect with DB but does not create the table)
PS. this the first time using MySql databases
this is my entity:
package com.example.bankingapp.model;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
public class Account {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String accountHolderName;
private double balance;
}
my application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/banking_app
spring.datasource.username=root
spring.datasource.password=Mysql@123
spring.jpa.hibernate.dll-auto=create
My dependencies:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
the logs:
:: Spring Boot :: (v3.2.4)
2024-03-28T17:31:00.041-04:00 INFO 24468 --- [ main] c.e.bankingapp.BankingAppApplication : Starting BankingAppApplication using Java 21 with PID 24468 (C:UsersmouhssinDesktopSPRINGbanking-apptargetclasses started by mouhssin in C:UsersmouhssinDesktopSPRINGbanking-app)
2024-03-28T17:31:00.048-04:00 INFO 24468 --- [ main] c.e.bankingapp.BankingAppApplication : No active profile set, falling back to 1 default profile: "default"
2024-03-28T17:31:01.646-04:00 INFO 24468 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2024-03-28T17:31:01.688-04:00 INFO 24468 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 22 ms. Found 0 JPA repository interfaces.
2024-03-28T17:31:02.978-04:00 INFO 24468 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http)
2024-03-28T17:31:02.997-04:00 INFO 24468 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2024-03-28T17:31:02.998-04:00 INFO 24468 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.19]
2024-03-28T17:31:03.102-04:00 INFO 24468 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2024-03-28T17:31:03.104-04:00 INFO 24468 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2921 ms
2024-03-28T17:31:03.515-04:00 INFO 24468 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2024-03-28T17:31:04.792-04:00 INFO 24468 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@3a4aadf8
2024-03-28T17:31:04.803-04:00 INFO 24468 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2024-03-28T17:31:05.115-04:00 INFO 24468 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2024-03-28T17:31:05.303-04:00 INFO 24468 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.4.4.Final
2024-03-28T17:31:05.396-04:00 INFO 24468 --- [ main] o.h.c.internal.RegionFactoryInitiator : HHH000026: Second-level cache disabled
2024-03-28T17:31:06.383-04:00 INFO 24468 --- [ main] o.s.o.j.p.SpringPersistenceUnitInfo : No LoadTimeWeaver setup: ignoring JPA class transformer
2024-03-28T17:31:08.171-04:00 INFO 24468 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
2024-03-28T17:31:08.174-04:00 INFO 24468 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2024-03-28T17:31:08.253-04:00 WARN 24468 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2024-03-28T17:31:09.126-04:00 INFO 24468 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path ''
2024-03-28T17:31:09.143-04:00 INFO 24468 --- [ main] c.e.bankingapp.BankingAppApplication : Started BankingAppApplication in 9.973 seconds (process running for 10.971)
expecting a table to be created after starting the springboot application, but that not the case
2
Answers
The mistake was a typo: was
spring.jpa.hibernate.dll-auto=create
instesd ofspring.jpa.hibernate.ddl-auto=update
ddl != dll
changes to be made:
and for the properties :