Issue: I was unable to auto-generate employee schema
Below is the error log which I copied from console instead of entire stacktrace:
java.sql.SQLSyntaxErrorException: Unknown database ’employee’
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.30.jar:8.0.30]
2024-04-26T14:00:13.755+05:30 WARN 59882 — [SpringbootmysqlApr24] [ restartedMain] o.h.e.j.e.i.JdbcEnvironmentInitiator : HHH000342: Could not obtain connection to query metadata
java.lang.NullPointerException: Cannot invoke “org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(java.sql.SQLException, String)” because the return value of “org.hibernate.resource.transaction.backend.jdbc.internal.JdbcIsolationDelegate.sqlExceptionHelper()” is null
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘entityManagerFactory’ defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.SQLGrammarException: Unable to open JDBC Connection for DDL execution [Unknown database ’employee’] [n/a]
Caused by: jakarta.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.SQLGrammarException: Unable to open JDBC Connection for DDL execution [Unknown database ’employee’] [n/a]
Caused by: org.hibernate.exception.SQLGrammarException: Unable to open JDBC Connection for DDL execution [Unknown database ’employee’] [n/a]
application.properties file:
spring.application.name=SpringbootmysqlApr24
spring.devtools.restart.enabled=true
#spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.show-sql = true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.dll-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/employee?useSSL=false
spring.datasource.username=root
spring.datasource.password=vinod123
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
#spring.jpa.properties.hibernate.dialect.format_sql = true
Employee.java:
package com.mycompany.entity;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Entity
@Table(name="emp")
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Employee {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long employeeId;
private String employeeName;
}
Vinod Y is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.