Issue
I am new to Springboot and I am trying to create a simple example Account entity class.
Ma20099449BankApplication.java class
@SpringBootApplication
public class Ma20099449BankApplication {
public static void main(String[] args) {
// SpringApplication.run(Ma20099449BankApplication.class, args);
// System.out.println("I am working");
ApplicationContext context = SpringApplication.run(Ma20099449BankApplication.class, args);
System.out.println("I have started !!!!");
}
}
Account.java class
package ma20099449.foundation.bank.ma20099449_bank.Entities;
import javax.persistence.*;
@Entity
@Table(name = "Account")
public class Account {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
public int accountNumber;
public String accountType;
public int balance;
//I have skipped getters, constructores and to string method.
}
AccountRepository.java class
package ma20099449.foundation.bank.ma20099449_bank.Dao;
import ma20099449.foundation.bank.ma20099449_bank.Entities.Account;
import org.springframework.data.repository.CrudRepository;
public interface AccountRepository extends CrudRepository<Account,Integer> {
}
Application.properties file
#configuring application name
spring.application.name=ma20099449_bank
#configuring port
server.port=8081
#configurations of data source
spring.datasource.name=bank_project# it is name of datasource property, not name of database, we give it unique name
spring.datasource.url=jdbc:mysql://localhost:3306/bank
# jdbc is protocol
# mysql is subprotocol
# and test is name of database to which we want to connect
spring.datasource.username=root
spring.datasource.password=1234
#If we don't have password then don't write this property
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
# if table is not created so we will automatically create a table using hibernate in the database using below command
spring.jpa.hibernate.ddl-auto=update #it will automatically create tables for all declared entities
When I am trying to run this application, I am getting below error
PS F:\Project2020\Wipro_Project_Bank\ma20099449_bank> f:; cd 'f:\Project2020\Wipro_Project_Bank\ma20099449_bank'; & 'c:\Users\hp\.vscode\extensions\vscjava.vscode-java-debug-0.35.0\scripts\launcher.bat' 'C:\Program Files\Java\jdk-15.0.1\bin\java.exe' '-XX:+ShowCodeDetailsInExceptionMessages' '-Dfile.encoding=UTF-8' '@C:\Users\hp\AppData\Local\Temp\cp_7z9d3w5z7jwf78fszsmd8j80n.argfile' 'ma20099449.foundation.bank.ma20099449_bank.Ma20099449BankApplication'
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.3)
2021-08-01 18:57:12.332 INFO 13324 --- [ restartedMain] m.f.b.m.Ma20099449BankApplication : Starting Ma20099449BankApplication using Java 15.0.1 on LAPTOP-RP0N4VRN with PID 13324 (F:\Project2020\Wipro_Project_Bank\ma20099449_bank\target\classes started by hp in F:\Project2020\Wipro_Project_Bank\ma20099449_bank)
2021-08-01 18:57:12.353 INFO 13324 --- [ restartedMain] m.f.b.m.Ma20099449BankApplication : No active profile set, falling back to default profiles: default
2021-08-01 18:57:12.504 INFO 13324 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2021-08-01 18:57:12.506 INFO 13324 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2021-08-01 18:57:13.895 INFO 13324 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-08-01 18:57:13.987 INFO 13324 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 69 ms. Found 1 JPA repository interfaces.
2021-08-01 18:57:15.224 INFO 13324 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with
port(s): 8081 (http)
2021-08-01 18:57:15.247 INFO 13324 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-08-01 18:57:15.247 INFO 13324 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.50]
2021-08-01 18:57:15.424 INFO 13324 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-08-01 18:57:15.426 INFO 13324 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2903 ms
2021-08-01 18:57:15.707 INFO 13324 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-08-01 18:57:15.795 INFO 13324 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.32.Final
2021-08-01 18:57:16.022 INFO 13324 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-08-01 18:57:16.186 INFO 13324 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : bank_project# it is name of datasource property, not name of database, we give it unique name - Starting...
2021-08-01 18:57:16.685 INFO 13324 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : bank_project# it is name of datasource property, not name of database, we give it unique name - Start completed.
2021-08-01 18:57:16.714 INFO 13324 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL57Dialect
2021-08-01 18:57:17.194 WARN 13324 --- [ restartedMain] o.h.b.i.SessionFactoryOptionsBuilder : Unrecognized hibernate.hbm2ddl.auto value: 'update #it will automatically create tables for all declared entities'. Supported values include 'create', 'create-drop', 'create-only', 'drop', 'update', 'none' and 'validate'. Ignoring
2021-08-01 18:57:17.720 ERROR 13324 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is java.lang.IllegalArgumentException: Unrecognized legacy `hibernate.hbm2ddl.auto` value : `update #it will automatically create tables for
all declared entities`
2021-08-01 18:57:17.722 WARN 13324 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException:
[PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is java.lang.IllegalArgumentException:
Unrecognized legacy `hibernate.hbm2ddl.auto` value : `update #it will automatically create tables for all declared entities`
2021-08-01 18:57:17.727 INFO 13324 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : bank_project# it is name of datasource property, not name of database, we give it unique name - Shutdown initiated...
2021-08-01 18:57:17.751 INFO 13324 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : bank_project# it is name of datasource property, not name of database, we give it unique name - Shutdown completed.
2021-08-01 18:57:17.758 INFO 13324 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2021-08-01 18:57:17.778 INFO 13324 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-08-01 18:57:17.813 ERROR 13324 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is java.lang.IllegalArgumentException: Unrecognized legacy `hibernate.hbm2ddl.auto` value : `update #it will automatically create tables for all declared entities`
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) ~[spring-context-5.3.9.jar:5.3.9]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) ~[spring-context-5.3.9.jar:5.3.9]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.9.jar:5.3.9]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.3.jar:2.5.3]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-2.5.3.jar:2.5.3]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-2.5.3.jar:2.5.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[spring-boot-2.5.3.jar:2.5.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-2.5.3.jar:2.5.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) ~[spring-boot-2.5.3.jar:2.5.3]
at ma20099449.foundation.bank.ma20099449_bank.Ma20099449BankApplication.main(Ma20099449BankApplication.java:13) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.5.3.jar:2.5.3]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is java.lang.IllegalArgumentException: Unrecognized legacy `hibernate.hbm2ddl.auto` value : `update #it will automatically create tables for all declared entities`
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:421) ~[spring-orm-5.3.9.jar:5.3.9]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) ~[spring-orm-5.3.9.jar:5.3.9]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1845) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1782) ~[spring-beans-5.3.9.jar:5.3.9]
... 21 common frames omitted
Caused by: java.lang.IllegalArgumentException: Unrecognized legacy `hibernate.hbm2ddl.auto` value : `update #it will automatically create tables for all declared entities`
at org.hibernate.tool.schema.Action.interpretHbm2ddlSetting(Action.java:181) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator$ActionGrouping.interpret(SchemaManagementToolCoordinator.java:490) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:53) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:318) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:468) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1259) ~[hibernate-core-5.4.32.Final.jar:5.4.32.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) ~[spring-orm-5.3.9.jar:5.3.9]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.3.9.jar:5.3.9]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) ~[spring-orm-5.3.9.jar:5.3.9]
... 25 common frames omitted
PS F:\Project2020\Wipro_Project_Bank\ma20099449_bank>
Please help me with this code. I am new to springboot, not able to find the proper error. I am using MySQL DB.
Solution
It seems that your Application.propertiesfile has a wrong key value, change this line: spring.jpa.hibernate.ddl-auto=update #it will automatically create tables for all declared entities
for it:
spring.jpa.hibernate.ddl-auto=update
#it will automatically create tables for all declared entities
try to not comment in front of the value, I think it can be the problem because your error log:
Caused by: java.lang.IllegalArgumentException: Unrecognized legacy hibernate.hbm2ddl.auto
value : update #it will automatically create tables for all declared entities
Answered By - Wander