Spring boot MySql program that is able to connect (I believe) but isn’t able to create the entity table.
Pom.xml-
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.0-M2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>dev.devin</groupId>
<artifactId>toDoApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>toDoApp</name>
<description>Backend application using mysql workbench bc xampp sucks</description>
<properties>
<java.version>17</java.version>
</properties>
<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>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
Application.properties file-
spring.datasource.url=jdbc:mysql://localhost:3306/db
spring.datasource.username=root
spring.datasource.password=0000
spring.datasource.driver.class-name=com.mysql.cj.jdbc.Driver
spring.jpa.show-sql=true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl.auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
spring.jpa.defer-datasource-initialization=true
spring.datasource.initialization-mode=always
Entity file (I manually added getters/setters/constructors to rule out lombok issues)-
package model;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Entity
@Table(name = "TASKS")
@Data
public class Task {
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(name = "TITLE")
private String title;
@Column(name = "BODY")
private String body;
public Task() {
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
}
terminal when I run-
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _
( ( )___ | '_ | '_| | '_ / _` |
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |___, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.2.0-M2)
2023-09-08T23:31:59.514-04:00 INFO 17088 --- [ main] dev.devin.toDoApp.ToDoAppApplication : Starting ToDoAppApplication using Java 17.0.8 with PID 17088 (C:UsersdevinOneDriveDesktoptoDoApptoDoApptargetclasses started by devin in C:UsersdevinOneDriveDesktoptoDoApp)
2023-09-08T23:31:59.519-04:00 INFO 17088 --- [ main] dev.devin.toDoApp.ToDoAppApplication : No active profile set, falling back to 1 default profile: "default"
2023-09-08T23:32:00.129-04:00 INFO 17088 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-09-08T23:32:00.157-04:00 INFO 17088 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 16 ms. Found 0 JPA repository interfaces.
2023-09-08T23:32:00.751-04:00 INFO 17088 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http)
2023-09-08T23:32:00.757-04:00 INFO 17088 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-09-08T23:32:00.758-04:00 INFO 17088 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.12]
2023-09-08T23:32:00.849-04:00 INFO 17088 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-09-08T23:32:00.851-04:00 INFO 17088 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1277 ms
2023-09-08T23:32:00.998-04:00 INFO 17088 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2023-09-08T23:32:01.284-04:00 INFO 17088 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@5d7d8613
2023-09-08T23:32:01.285-04:00 INFO 17088 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2023-09-08T23:32:01.324-04:00 INFO 17088 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2023-09-08T23:32:01.369-04:00 INFO 17088 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.2.7.Final
2023-09-08T23:32:01.370-04:00 INFO 17088 --- [ main] org.hibernate.cfg.Environment : HHH000406: Using bytecode reflection optimizer
2023-09-08T23:32:01.507-04:00 INFO 17088 --- [ main] o.h.b.i.BytecodeProviderInitiator : HHH000021: Bytecode provider name : bytebuddy
2023-09-08T23:32:01.661-04:00 INFO 17088 --- [ main] o.s.o.j.p.SpringPersistenceUnitInfo : No LoadTimeWeaver setup: ignoring JPA class transformer
2023-09-08T23:32:01.817-04:00 INFO 17088 --- [ main] o.h.b.i.BytecodeProviderInitiator : HHH000021: Bytecode provider name : bytebuddy
2023-09-08T23:32:02.054-04:00 INFO 17088 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2023-09-08T23:32:02.061-04:00 INFO 17088 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2023-09-08T23:32:02.108-04:00 WARN 17088 --- [ 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
2023-09-08T23:32:02.534-04:00 INFO 17088 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path ''
2023-09-08T23:32:02.540-04:00 INFO 17088 --- [ main] dev.devin.toDoApp.ToDoAppApplication : Started ToDoAppApplication in 3.364 seconds (process running for 3.706)
Im using mysql 8 with workbench as well.
This is my first stackoverflow post and hopefully my last lol.
let me know if you need any information and thank you for taking the time out of your day.
I tried changing spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect to all the different versions of dialects. note that spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect tells me to change it back to the former version due to deprecation. This is all I’ve really tried as I’m pretty certain its a hibernation issue because the terminal says that it’s able to establish a jdbc connection (although im not quite sure what that even means).
2
Answers
There is a typo in the configuration.
Use:
This config has default value. For embedded / in-memory databases (e.g. h2) is
create-drop
, othertwise ("real" databases)none
.your entity class is single package of model . check your entity class must be in same package or sub-package of a class that annotated with @SpringBootApplication or @EnableAutoConfiguration