On running my springboot application hibernate is creating new columns.
Below is my entity class
#Entity
#Table(name="contst_games")
public class ContestGames {
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
#Column(name="id")
private int id;
#Column(name="cntstName")
private String contestName;
#Column(name="cntstType")
private String contestType;
#Column(name="phne")
private int phoneNumbr;
// getters and setters
#Override
public String toString() {
return "ContestGames [id=" + id + ", contestName=" + contestName + ", contestType=" + contestType + "]";
}
}
Below is the setup of properties
# ==========================================================================
# = JPA / HIBERNATE
# ==========================================================================
spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect
spring.jpa.show-sql = true
#60 sec
spring.datasource.hikari.connection-timeout=60000
# max 5
spring.datasource.hikari.maximum-pool-size=5
spring.jpa.hibernate.ddl-auto=update
#============================================================================
Below is the newly created table
'id', 'int(11)', 'NO', 'PRI', NULL, 'auto_increment'
'cntstName', 'varchar(255)', 'YES', '', NULL, ''
'cntstType', 'varchar(255)', 'YES', '', NULL, ''
'phne', 'int(11)', 'YES', '', NULL, ''
'cntst_name', 'varchar(255)', 'YES', '', NULL, ''
'cntst_type', 'varchar(255)', 'YES', '', NULL, ''
Below is the alter query that is being run on running the application.
2019-11-28 13:09:23.092 INFO 10615 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2019-11-28 13:09:23.158 INFO 10615 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.4.8.Final}
2019-11-28 13:09:23.344 INFO 10615 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2019-11-28 13:09:23.446 INFO 10615 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-11-28 13:09:23.450 WARN 10615 --- [ main] com.zaxxer.hikari.util.DriverDataSource : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
2019-11-28 13:09:23.669 INFO 10615 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-11-28 13:09:23.688 INFO 10615 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
Hibernate: alter table contst_games add column cntst_name varchar(255)
Hibernate: alter table contst_games add column cntst_type varchar(255)
2019-11-28 13:09:24.867 INFO 10615 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2019-11-28 13:09:24.891 INFO 10615 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-11-28 13:09:25.482 WARN 10615 --- [ 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
Two new columns cntst_name and cntst_type are being created at runtime. Ideally no new column should be added since the table already exists and spring.jpa.hibernate.ddl-auto=update. Also to be noted no new column for phone number is being created.
That's because of Hibernate&Spring Boot Naming Strategies.
(more info: https://www.jpa-buddy.com/blog/hibernate-naming-strategies-jpa-specification-vs-springboot-opinionation)
So,
the right way is to name your columns strictly in a snake_case, NOT camelCase or PascalCase.
Related
I have just created the spring boot application from spring initializer and execute it in intellij.But I am facing some error. Can anyone please help me to solve the error?
package com.demo.grocery;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class GroceryApplication {
public static void main(String[] args) {
SpringApplication.run(GroceryApplication.class, args);
}
}
And this is the error I am facing
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.2)
2022-07-29 22:12:46.331 INFO 14136 --- [ main] com.demo.grocery.GroceryApplication : Starting GroceryApplication using Java 11.0.13 on DESKTOP-MQ2O3FR with PID 14136 (C:\Users\keerthi\Downloads\grocery\target\classes started by keerthi in C:\Users\keerthi\Downloads\grocery)
2022-07-29 22:12:46.336 INFO 14136 --- [ main] com.demo.grocery.GroceryApplication : No active profile set, falling back to 1 default profile: "default"
2022-07-29 22:12:47.288 INFO 14136 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-07-29 22:12:47.306 INFO 14136 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 7 ms. Found 0 JPA repository interfaces.
2022-07-29 22:12:48.437 INFO 14136 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-07-29 22:12:48.463 INFO 14136 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-07-29 22:12:48.463 INFO 14136 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.65]
2022-07-29 22:12:48.721 INFO 14136 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-07-29 22:12:48.721 INFO 14136 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2267 ms
2022-07-29 22:12:48.832 WARN 14136 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2022-07-29 22:12:48.839 INFO 14136 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-07-29 22:12:48.868 INFO 14136 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-07-29 22:12:48.897 ERROR 14136 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
Process finished with exit code 1
I have tried most of the solutions from stackoverflow, help me to solve this error
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/db_example
spring.datasource.username=springuser
spring.datasource.password=ThePassword
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#spring.jpa.show-sql: true
Paste this in your application properties file in the resource folder.
Change the database name in the second line and also change the username and password according to your database.
I looked into similar issues and tried to do different options as mentioned in the prior threads, but not able to fix it. I have the error below, can somebody help me to fix this issue.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.11.RELEASE)
2020-12-08 15:05:30.602 INFO 11076 --- [ main] c.p.c.ConferenceDemoApplication : Starting ConferenceDemoApplication on DESKTOP-3RN8P39 with PID 11076 (C:\Users\tania\Downloads\conference-demo\conference-demo\target\classes started by tania in C:\Users\tania\Downloads\conference-demo)
2020-12-08 15:05:30.607 INFO 11076 --- [ main] c.p.c.ConferenceDemoApplication : No active profile set, falling back to default profiles: default
2020-12-08 15:05:32.039 INFO 11076 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-12-08 15:05:32.162 INFO 11076 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 109ms. Found 2 JPA repository interfaces.
2020-12-08 15:05:33.208 INFO 11076 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-12-08 15:05:33.220 INFO 11076 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-12-08 15:05:33.221 INFO 11076 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.39]
2020-12-08 15:05:33.339 INFO 11076 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-12-08 15:05:33.339 INFO 11076 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2655 ms
2020-12-08 15:05:33.595 INFO 11076 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-12-08 15:05:33.655 INFO 11076 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.22.Final
2020-12-08 15:05:33.775 INFO 11076 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2020-12-08 15:05:33.866 INFO 11076 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-12-08 15:05:34.392 INFO 11076 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-12-08 15:05:34.406 WARN 11076 --- [ main] o.h.e.j.e.i.JdbcEnvironmentInitiator : HHH000342: Could not obtain connection to query metadata : Unable to resolve name [org.hibernate.dialect.mysqlDialect] as strategy [org.hibernate.dialect.Dialect]
2020-12-08 15:05:34.409 WARN 11076 --- [ main] 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 org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
2020-12-08 15:05:34.410 INFO 11076 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2020-12-08 15:05:34.413 INFO 11076 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2020-12-08 15:05:34.416 INFO 11076 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-12-08 15:05:34.426 INFO 11076 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-12-08 15:05:34.432 ERROR 11076 --- [ main] 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 org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1794) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1109) ~[spring-context-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.11.RELEASE.jar:2.2.11.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.11.RELEASE.jar:2.2.11.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405) ~[spring-boot-2.2.11.RELEASE.jar:2.2.11.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.11.RELEASE.jar:2.2.11.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.11.RELEASE.jar:2.2.11.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.11.RELEASE.jar:2.2.11.RELEASE]
at com.pluralsight.conferencedemo.ConferenceDemoApplication.main(ConferenceDemoApplication.java:10) ~[classes/:na]
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:275) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:152) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:176) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:118) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1224) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1255) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) ~[spring-orm-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391) ~[spring-orm-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:378) ~[spring-orm-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1790) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
... 16 common frames omitted
Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.dialect.mysqlDialect] as strategy [org.hibernate.dialect.Dialect]
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:156) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:239) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:183) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:170) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:164) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:74) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:51) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
... 33 common frames omitted
Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [org.hibernate.dialect.mysqlDialect]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:133) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:152) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
... 43 common frames omitted
Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.dialect.mysqlDialect
at org.hibernate.boot.registry.classloading.internal.AggregatedClassLoader.findClass(AggregatedClassLoader.java:210) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[na:na]
at java.base/java.lang.Class.forName0(Native Method) ~[na:na]
at java.base/java.lang.Class.forName(Class.java:468) ~[na:na]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:130) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
... 44 common frames omitted
Process finished with exit code 1
Pom.xml application properties
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.2.11.RELEASE
com.example
demo
0.0.1-SNAPSHOT
demo
Demo project for Spring Boot
<properties>
<java.version>11</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>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.3.Final</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.27.0-GA</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
I have been trying different options to get rid of this error, but it appears that the issue is with the mapping. Below are the model outputs, need your help in resolving this issue.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.11.RELEASE)
2020-12-09 18:16:25.136 INFO 16144 --- [ main] c.p.c.ConferenceDemoApplication : Starting ConferenceDemoApplication on DESKTOP-3RN8P39 with PID 16144 (C:\Users\tania\Downloads\conference-demo\conference-demo\target\classes started by tania in C:\Users\tania\Downloads\conference-demo)
2020-12-09 18:16:25.140 INFO 16144 --- [ main] c.p.c.ConferenceDemoApplication : No active profile set, falling back to default profiles: default
2020-12-09 18:16:26.448 INFO 16144 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-12-09 18:16:26.577 INFO 16144 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 114ms. Found 2 JPA repository interfaces.
2020-12-09 18:16:27.536 INFO 16144 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-12-09 18:16:27.552 INFO 16144 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-12-09 18:16:27.552 INFO 16144 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.39]
2020-12-09 18:16:27.676 INFO 16144 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-12-09 18:16:27.676 INFO 16144 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2437 ms
2020-12-09 18:16:27.898 INFO 16144 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-12-09 18:16:27.946 INFO 16144 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.22.Final
2020-12-09 18:16:28.062 INFO 16144 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-12-09 18:16:28.154 INFO 16144 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-12-09 18:16:28.501 INFO 16144 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-12-09 18:16:28.517 INFO 16144 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
2020-12-09 18:16:28.827 WARN 16144 --- [ main] 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 org.hibernate.AnnotationException: #OneToOne or #ManyToOne on com.pluralsight.conferencedemo.models.Session.speakers references an unknown entity: java.util.List
2020-12-09 18:16:28.827 INFO 16144 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2020-12-09 18:16:28.854 INFO 16144 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2020-12-09 18:16:28.854 INFO 16144 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-12-09 18:16:28.863 INFO 16144 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-12-09 18:16:28.872 ERROR 16144 --- [ main] 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 org.hibernate.AnnotationException: #OneToOne or #ManyToOne on com.pluralsight.conferencedemo.models.Session.speakers references an unknown entity: java.util.List
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1794) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1109) ~[spring-context-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.11.RELEASE.jar:2.2.11.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.11.RELEASE.jar:2.2.11.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405) ~[spring-boot-2.2.11.RELEASE.jar:2.2.11.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.11.RELEASE.jar:2.2.11.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.11.RELEASE.jar:2.2.11.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.11.RELEASE.jar:2.2.11.RELEASE]
at com.pluralsight.conferencedemo.ConferenceDemoApplication.main(ConferenceDemoApplication.java:10) ~[classes/:na]
Caused by: org.hibernate.AnnotationException: #OneToOne or #ManyToOne on com.pluralsight.conferencedemo.models.Session.speakers references an unknown entity: java.util.List
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:97) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processEndOfQueue(InFlightMetadataCollectorImpl.java:1823) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processFkSecondPassesInOrder(InFlightMetadataCollectorImpl.java:1767) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1655) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:286) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1224) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1255) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) ~[spring-orm-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391) ~[spring-orm-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:378) ~[spring-orm-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1790) ~[spring-beans-5.2.10.RELEASE.jar:5.2.10.RELEASE]
... 16 common frames omitted
Process finished with exit code 1
Model1
package com.pluralsight.conferencedemo.models;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import javax.persistence.*;
import java.util.List;
#Entity(name="sessions")
public class Session {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long session_id;
#Column(name="session_name", nullable = false)
private String session_name;
#Column(name="session_description", nullable = false)
private String session_description;
#Column(name="session_length", nullable = false)`enter code here`
private Integer session_length;
#ManyToMany
#JoinTable(
name="session_speakers",
joinColumns = #JoinColumn(name="session_id"),
inverseJoinColumns = #JoinColumn(name="speaker_id")
)
private List<Speakers> speakers;
public Session(){
}
public List<Speakers> getSpeakers() {
return speakers;
}
public void setSpeakers(List<Speakers> speakers) {
this.speakers = speakers;
}
public Long getSession_id() {
return session_id;
}
public void setSession_id(Long session_id) {
this.session_id = session_id;
}
public String getSession_name() {
return session_name;
}
public void setSession_name(String session_name) {
this.session_name = session_name;
}
public String getSession_description() {
return session_description;
}
public void setSession_description(String session_description) {
this.session_description = session_description;
}
public Integer getSession_length() {
return session_length;
}
public void setSession_length(Integer session_length) {
this.session_length = session_length;
}
}
Model2
package com.pluralsight.conferencedemo.models;
import javax.persistence.*;
import java.util.List;
#Entity(name="speakers")
public class Speakers {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long speaker_id;
#Column(name="first_name", nullable = false)
private String first_name;
#Column(name="last_name", nullable = false)
private String last_name;
#Column(name="title", nullable = false)
private String title;
#Column(name="company", nullable = false)
private String company;
#Column(name="speaker_bio", nullable = false)
private String speaker_bio;
private byte[] speaker_photo;
#ManyToMany(mappedBy= "speakers")
private List<Session> session;
public Speakers(){
}
public byte[] getSpeaker_photo() {
return speaker_photo;
}
public void setSpeaker_photo(byte[] speaker_photo) {
this.speaker_photo = speaker_photo;
}
public List<Session> getSession() {
return session;
}
public void setSession(List<Session> session) {
this.session = session;
}
public Long getSpeaker_id() {
return speaker_id;
}
public void setSpeaker_id(Long speaker_id) {
this.speaker_id = speaker_id;
}
public String getFirst_name() {
return first_name;
}
public void setFirst_name(String first_name) {
this.first_name = first_name;
}
public String getLast_name() {
return last_name;
}
public void setLast_name(String last_name) {
this.last_name = last_name;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String getSpeaker_bio() {
return speaker_bio;
}
public void setSpeaker_bio(String speaker_bio) {
this.speaker_bio = speaker_bio;
}
}
I'm trying to create tables on my remote db, but It doesn't make any query on it.
Actually when I'm typing my db password wrong it gives me an error, so I assume that somehow it is connecting but not serializing any entity.
Here is my 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>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.palmieri</groupId>
<artifactId>InstaPalm</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>InstaPalm</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>14</java.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<type>pom</type>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
<version>2.3.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.21</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<version>2.3.4.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Here is my entity class User
package com.palmieri.InstaPalm.entities;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Date;
import java.util.List;
#Entity
#Table(name = "photo")
public class Photo implements Serializable {
private static final long serialVersionUID = 6470094278127188729L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
#Column(name = "data", nullable = false)
private Date data;
#ManyToOne( fetch = FetchType.EAGER)
private User user;
#Column(name="link", nullable = false)
private String link;
#OneToMany(mappedBy = "photo", fetch = FetchType.EAGER)
private List<Like> likes;
#OneToMany(mappedBy = "photo", fetch = FetchType.EAGER)
private List<Comment> comments;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Date getData() {
return data;
}
public void setData(Date data) {
this.data = data;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public List<Like> getLikes() {
return likes;
}
public void setLikes(List<Like> likes) {
this.likes = likes;
}
public List<Comment> getComments() {
return comments;
}
public void setComments(List<Comment> comments) {
this.comments = comments;
}
}
And my application.properties
## Database Properties
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url = jdbc:mysql://sql2.freemysqlhosting.net:3306/XXX?useSSL=false
spring.datasource.username = XXXXX
spring.datasource.password = XXXXX
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.open-in-view=false
spring.jpa.show-sql=true
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = none
I'm sure i'm missing some configuration or some property but I cant figure out which one, maybe I mismatched the packages? thank you for your response
EDIT 1
Here is my log
2020-09-23 14:54:49.807 INFO 14620 --- [ restartedMain] c.p.InstaPalm.InstaPalmApplication : Starting InstaPalmApplication on SI-W-00446 with PID 14620 (C:\Users\SI2001\IdeaProjects\InstaPalm\InstaPalm\target\classes started by SI2001 in C:\Users\SI2001\IdeaProjects\InstaPalm\InstaPalm)
2020-09-23 14:54:49.809 INFO 14620 --- [ restartedMain] c.p.InstaPalm.InstaPalmApplication : No active profile set, falling back to default profiles: default
2020-09-23 14:54:49.809 DEBUG 14620 --- [ restartedMain] o.s.boot.SpringApplication : Loading source class com.palmieri.InstaPalm.InstaPalmApplication
2020-09-23 14:54:49.919 DEBUG 14620 --- [ restartedMain] o.s.b.c.c.ConfigFileApplicationListener : Loaded config file 'file:/C:/Users/SI2001/IdeaProjects/InstaPalm/InstaPalm/target/classes/application.properties' (classpath:/application.properties)
2020-09-23 14:54:49.921 DEBUG 14620 --- [ restartedMain] o.s.b.devtools.restart.ChangeableUrls : Matching URLs for reloading : [file:/C:/Users/SI2001/IdeaProjects/InstaPalm/InstaPalm/target/classes/]
2020-09-23 14:54:49.921 DEBUG 14620 --- [ restartedMain] o.s.b.d.settings.DevToolsSettings : Included patterns for restart : []
2020-09-23 14:54:49.921 DEBUG 14620 --- [ restartedMain] o.s.b.d.settings.DevToolsSettings : Excluded patterns for restart : [/spring-boot-starter-[\w-]+/, /spring-boot/(bin|build|out)/, /spring-boot-starter/(bin|build|out)/, /spring-boot-devtools/(bin|build|out)/, /spring-boot-actuator/(bin|build|out)/, /spring-boot-autoconfigure/(bin|build|out)/]
2020-09-23 14:54:49.922 INFO 14620 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-09-23 14:54:49.922 INFO 14620 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2020-09-23 14:54:49.922 DEBUG 14620 --- [ restartedMain] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#4d5a23dd
2020-09-23 14:54:51.024 INFO 14620 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2020-09-23 14:54:51.046 INFO 14620 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 14ms. Found 0 JPA repository interfaces.
2020-09-23 14:54:51.574 DEBUG 14620 --- [ restartedMain] .s.b.w.e.t.TomcatServletWebServerFactory : Code archive: C:\Users\SI2001\.m2\repository\org\springframework\boot\spring-boot\2.3.4.RELEASE\spring-boot-2.3.4.RELEASE.jar
2020-09-23 14:54:51.575 DEBUG 14620 --- [ restartedMain] .s.b.w.e.t.TomcatServletWebServerFactory : Code archive: C:\Users\SI2001\.m2\repository\org\springframework\boot\spring-boot\2.3.4.RELEASE\spring-boot-2.3.4.RELEASE.jar
2020-09-23 14:54:51.575 DEBUG 14620 --- [ restartedMain] .s.b.w.e.t.TomcatServletWebServerFactory : None of the document roots [src/main/webapp, public, static] point to a directory and will be ignored.
2020-09-23 14:54:51.641 INFO 14620 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-09-23 14:54:51.651 INFO 14620 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-09-23 14:54:51.651 INFO 14620 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.38]
2020-09-23 14:54:51.797 INFO 14620 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-09-23 14:54:51.798 DEBUG 14620 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]
2020-09-23 14:54:51.798 INFO 14620 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1876 ms
2020-09-23 14:54:51.927 DEBUG 14620 --- [ restartedMain] o.s.b.w.s.ServletContextInitializerBeans : Mapping filters: filterRegistrationBean urls=[/*] order=-2147483647, characterEncodingFilter urls=[/*] order=-2147483648, formContentFilter urls=[/*] order=-9900, requestContextFilter urls=[/*] order=-105
2020-09-23 14:54:51.927 DEBUG 14620 --- [ restartedMain] o.s.b.w.s.ServletContextInitializerBeans : Mapping servlets: dispatcherServlet urls=[/]
2020-09-23 14:54:51.945 DEBUG 14620 --- [ restartedMain] o.s.b.a.m.w.servlet.WebMvcMetricsFilter : Filter 'webMvcMetricsFilter' configured for use
2020-09-23 14:54:51.945 DEBUG 14620 --- [ restartedMain] o.s.b.w.s.f.OrderedRequestContextFilter : Filter 'requestContextFilter' configured for use
2020-09-23 14:54:51.945 DEBUG 14620 --- [ restartedMain] s.b.w.s.f.OrderedCharacterEncodingFilter : Filter 'characterEncodingFilter' configured for use
2020-09-23 14:54:51.945 DEBUG 14620 --- [ restartedMain] o.s.b.w.s.f.OrderedFormContentFilter : Filter 'formContentFilter' configured for use
DEBUG StatusLogger org.slf4j.helpers.Log4jLoggerFactory is not on classpath. Good!
2020-09-23 14:54:52.109 INFO 14620 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-09-23 14:54:52.147 INFO 14620 --- [ task-1] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-09-23 14:54:52.200 INFO 14620 --- [ task-1] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.21.Final
2020-09-23 14:54:52.355 INFO 14620 --- [ task-1] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-09-23 14:54:52.361 DEBUG 14620 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : ControllerAdvice beans: 0 #ModelAttribute, 0 #InitBinder, 1 RequestBodyAdvice, 1 ResponseBodyAdvice
2020-09-23 14:54:52.415 DEBUG 14620 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : 2 mappings in 'requestMappingHandlerMapping'
2020-09-23 14:54:52.446 DEBUG 14620 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Patterns [/webjars/**, /**] in 'resourceHandlerMapping'
2020-09-23 14:54:52.459 DEBUG 14620 --- [ restartedMain] .m.m.a.ExceptionHandlerExceptionResolver : ControllerAdvice beans: 0 #ExceptionHandler, 1 ResponseBodyAdvice
2020-09-23 14:54:52.463 INFO 14620 --- [ task-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-09-23 14:54:53.132 INFO 14620 --- [ task-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-09-23 14:54:53.153 INFO 14620 --- [ task-1] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
2020-09-23 14:54:53.364 DEBUG 14620 --- [ restartedMain] inMXBeanRegistrar$SpringApplicationAdmin : Application Admin MBean registered with name 'org.springframework.boot:type=Admin,name=SpringApplication'
2020-09-23 14:54:53.411 DEBUG 14620 --- [ restartedMain] o.s.b.d.livereload.LiveReloadServer : Starting live reload server on port 35729
2020-09-23 14:54:53.413 INFO 14620 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2020-09-23 14:54:53.419 INFO 14620 --- [ restartedMain] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2020-09-23 14:54:53.479 INFO 14620 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-09-23 14:54:53.481 INFO 14620 --- [ restartedMain] DeferredRepositoryInitializationListener : Triggering deferred initialization of Spring Data repositories…
2020-09-23 14:54:53.482 INFO 14620 --- [ restartedMain] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
2020-09-23 14:54:53.500 INFO 14620 --- [ restartedMain] c.p.InstaPalm.InstaPalmApplication : Started InstaPalmApplication in 4.246 seconds (JVM running for 5.36)
2020-09-23 14:54:53.506 DEBUG 14620 --- [ restartedMain] o.s.boot.devtools.restart.Restarter : Creating new Restarter for thread Thread[main,5,main]
2020-09-23 14:54:53.506 DEBUG 14620 --- [ restartedMain] o.s.boot.devtools.restart.Restarter : Immediately restarting application
2020-09-23 14:54:53.506 DEBUG 14620 --- [ restartedMain] o.s.boot.devtools.restart.Restarter : Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader#1c3d316b
2020-09-23 14:54:53.506 DEBUG 14620 --- [ restartedMain] o.s.boot.devtools.restart.Restarter : Starting application com.palmieri.InstaPalm.InstaPalmApplication with URLs [file:/C:/Users/SI2001/IdeaProjects/InstaPalm/InstaPalm/target/classes/]
2020-09-23 14:54:54.064 INFO 14620 --- [ion(3)-10.8.2.7] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-09-23 14:54:54.064 INFO 14620 --- [ion(3)-10.8.2.7] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-09-23 14:54:54.064 DEBUG 14620 --- [ion(3)-10.8.2.7] o.s.web.servlet.DispatcherServlet : Detected StandardServletMultipartResolver
2020-09-23 14:54:54.071 DEBUG 14620 --- [ion(3)-10.8.2.7] o.s.web.servlet.DispatcherServlet : enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
2020-09-23 14:54:54.072 INFO 14620 --- [ion(3)-10.8.2.7] o.s.web.servlet.DispatcherServlet : Completed initialization in 8 ms
You can achieve your purpose by adding this
spring.jpa.hibernate.ddl-auto = create
But keep in mind that, everytime you start your application, it will delete all previous tables and data. So to avoid this, you just change it toupdate like this
spring.jpa.hibernate.ddl-auto = update
add createDatabaseIfNotExist=true to your db.url
spring.datasource.url = jdbc:mysql://sql2.freemysqlhosting.net:3306/XXX useSSL=false&createDatabaseIfNotExist=true
i think you need to use the following configurations in application.properties/application.yml file:
database:
name: yourdbname
spring:
jpa:
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: ######
password: ######
url: jdbc:mysql://sql2.freemysqlhosting.net:3306/${database.name}&useSSL=false&createDatabaseIfNotExist=true
If you want Hibernate to create your tables you should set the spring.jpa.hibernate.ddl-auto Property in your application.property file from none to create or update.
spring.jpa.hibernate.ddl-auto = create
It's better to create an empty database first using the SQL command if it's not available in your MySQL server.
Then run your application with the following property added into your application.properties file.
spring.jpa.hibernate.ddl-auto = update
As the update parameter will not drop your database and recreate it on each restart
I am writing my first springboot/jpa/mysql backend using STS.
I am following tutorial from :
https://www.youtube.com/playlist?list=PLdJYl6XU45uLIHaPBQEj-cEMynAl0oeiz
Code is:
Book.java
package com.lms.models;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
#Entity(name = "lms_tbl")
public class Book {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private long id;
#Column(name = "book_name")
private String bookName;
private String author;
#Column(name = "purchase_date")
private Date purchaseDate;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public Date getPurchaseDate() {
return purchaseDate;
}
public void setPurchaseDate(Date purchaseDate) {
this.purchaseDate = purchaseDate;
}
}
LmsRepository.java
package com.lms.dao;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.CrudRepository;
import com.lms.models.Book;
public interface LmsRepository extends JpaRepository<Book, Long>{
}
LmsService.java:
package com.lms.services;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lms.dao.LmsRepository;
import com.lms.models.Book;
#Service
public class LmsService {
#Autowired
private LmsRepository lmsRepository;
public Collection<Book> findAllBooks() {
List<Book> books = new ArrayList<Book>();
for(Book book : lmsRepository.findAll()) {
books.add(book);
}
return books;
}
public String addBook(Book book) {
lmsRepository.saveAndFlush(book);
return "added added";
}
}
MainRestController.java
package com.lms.controllers.rest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.lms.services.LmsService;
import java.util.Collection;
import com.lms.models.Book;
#RestController
public class MainRestController {
#Autowired
private LmsService lmsService;
#GetMapping(value = "/")
public String hello() {
return "Hello World!";
}
#GetMapping("/findAllBooks")
public Collection<Book> getAllBooks() {
return lmsService.findAllBooks();
}
#PostMapping("/postBook")
public String addNewBook(#RequestBody Book book) {
lmsService.addBook(book);
return "Added";
}
}
application.properties:
spring.mvc.view.prefix = /WEB-INF/jsp/
spring.mvc.view.suffix = .jsp
spring.datasource.url = jdbc:mysql://localhost:3306/lmsdb?useSSL=false
spring.datasource.username = root
spring.datasource.password = root639
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
spring.jpa.hibernate.ddl-auto= update
logging.level.org.hibernate.SQL = debug
When I start the main class as spring boot app , I get message:
2020-06-05 17:05:24.458 INFO 13300 --- [ main] com.lms.LmsApplication : Starting LmsApplication on BLR-FV2ZKC2 with PID 13300 (C:\Users\Jagrati.Agrawal\Documents\workspace-spring-tool-suite-4-4.6.2.RELEASE\LMS\target\classes started by Jagrati.Agrawal in C:\Users\Jagrati.Agrawal\Documents\workspace-spring-tool-suite-4-4.6.2.RELEASE\LMS)
2020-06-05 17:05:24.478 INFO 13300 --- [ main] com.lms.LmsApplication : No active profile set, falling back to default profiles: default
2020-06-05 17:05:26.853 INFO 13300 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2020-06-05 17:05:27.019 INFO 13300 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 151ms. Found 1 JPA repository interfaces.
2020-06-05 17:05:29.102 INFO 13300 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-06-05 17:05:29.118 INFO 13300 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-06-05 17:05:29.118 INFO 13300 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.35]
2020-06-05 17:05:30.604 INFO 13300 --- [ main] org.apache.jasper.servlet.TldScanner : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2020-06-05 17:05:30.612 INFO 13300 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-06-05 17:05:30.613 INFO 13300 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 6009 ms
2020-06-05 17:05:31.169 INFO 13300 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-06-05 17:05:31.530 INFO 13300 --- [ task-1] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-06-05 17:05:32.012 INFO 13300 --- [ task-1] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.15.Final
2020-06-05 17:05:32.621 WARN 13300 --- [ 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
2020-06-05 17:05:32.844 INFO 13300 --- [ task-1] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-06-05 17:05:33.282 INFO 13300 --- [ task-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-06-05 17:05:34.121 INFO 13300 --- [ task-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-06-05 17:05:34.211 INFO 13300 --- [ task-1] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
2020-06-05 17:05:37.695 DEBUG 13300 --- [ task-1] org.hibernate.SQL : create table hibernate_sequence (next_val bigint) type=MyISAM
2020-06-05 17:05:37.776 WARN 13300 --- [ task-1] o.h.t.s.i.ExceptionHandlerLoggedImpl : GenerationTarget encountered exception accepting command : Error executing DDL "create table hibernate_sequence (next_val bigint) type=MyISAM" via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table hibernate_sequence (next_val bigint) type=MyISAM" via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlString(AbstractSchemaMigrator.java:559) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlStrings(AbstractSchemaMigrator.java:504) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.createTable(AbstractSchemaMigrator.java:277) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl.performTablesMigration(GroupedSchemaMigratorImpl.java:71) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.performMigration(AbstractSchemaMigrator.java:207) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.java:114) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:184) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:73) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:314) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:468) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1249) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) [spring-orm-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) [spring-orm-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391) [spring-orm-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at java.util.concurrent.FutureTask.run(Unknown Source) ~[na:1.8.0_201]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[na:1.8.0_201]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[na:1.8.0_201]
at java.lang.Thread.run(Unknown Source) ~[na:1.8.0_201]
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'type=MyISAM' at line 1
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:764) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:648) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-3.4.5.jar:na]
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
... 18 common frames omitted
2020-06-05 17:05:37.777 DEBUG 13300 --- [ task-1] org.hibernate.SQL : insert into hibernate_sequence values ( 1 )
2020-06-05 17:05:37.913 WARN 13300 --- [ task-1] o.h.t.s.i.ExceptionHandlerLoggedImpl : GenerationTarget encountered exception accepting command : Error executing DDL "insert into hibernate_sequence values ( 1 )" via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "insert into hibernate_sequence values ( 1 )" via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlString(AbstractSchemaMigrator.java:559) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlStrings(AbstractSchemaMigrator.java:504) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.createTable(AbstractSchemaMigrator.java:277) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl.performTablesMigration(GroupedSchemaMigratorImpl.java:71) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.performMigration(AbstractSchemaMigrator.java:207) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.java:114) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:184) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:73) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:314) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:468) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1249) [hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) [spring-orm-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) [spring-orm-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391) [spring-orm-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at java.util.concurrent.FutureTask.run(Unknown Source) ~[na:1.8.0_201]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[na:1.8.0_201]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[na:1.8.0_201]
at java.lang.Thread.run(Unknown Source) ~[na:1.8.0_201]
Caused by: java.sql.SQLSyntaxErrorException: Table 'lmsdb.hibernate_sequence' doesn't exist
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:764) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:648) ~[mysql-connector-java-8.0.20.jar:8.0.20]
at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-3.4.5.jar:na]
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
... 18 common frames omitted
2020-06-05 17:05:37.915 INFO 13300 --- [ task-1] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-06-05 17:05:37.929 INFO 13300 --- [ task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-06-05 17:05:38.689 INFO 13300 --- [ main] pertySourcedRequestMappingHandlerMapping : Mapped URL path [/v2/api-docs] onto method [springfox.documentation.swagger2.web.Swagger2Controller#getDocumentation(String, HttpServletRequest)]
2020-06-05 17:05:39.115 INFO 13300 --- [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page template: index
2020-06-05 17:05:39.499 INFO 13300 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-06-05 17:05:39.501 INFO 13300 --- [ main] d.s.w.p.DocumentationPluginsBootstrapper : Context refreshed
2020-06-05 17:05:39.568 INFO 13300 --- [ main] d.s.w.p.DocumentationPluginsBootstrapper : Found 1 custom documentation plugin(s)
2020-06-05 17:05:39.661 INFO 13300 --- [ main] s.d.s.w.s.ApiListingReferenceScanner : Scanning for api listing references
2020-06-05 17:05:40.122 INFO 13300 --- [ main] DeferredRepositoryInitializationListener : Triggering deferred initialization of Spring Data repositories…
2020-06-05 17:05:40.300 INFO 13300 --- [ main] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
2020-06-05 17:05:40.325 INFO 13300 --- [ main] com.lms.LmsApplication : Started LmsApplication in 17.027 seconds (JVM running for 21.465)
So the app does get started with above error/warning messages and I am able to hit /findAllBooks thru swagger and it works fine, but when I hit /postBook, I get error on swagger "TypeError: Failed to fetch".
Please help.
I am working with a Spring Boot application . I have faced some issue related to org.hibernate.HibernateException: Missing column: auth_password in medxlabpro.appsettings
I have column in my PoJo class authpassword not auth_password. So why this type of issue coming in my application . Anyone can help me please. I have added JPA configuration and Log.
As per my concern i guess it is coming due to configuration mistake.
generate-ddl: false
hibernate:
ddl-auto: validate
:: Spring Boot :: (v1.2.1.RELEASE)
2016-06-21 19:31:52.733 INFO 8196 --- [ main] org.sam.application.Application : Starting Application on DESKTOP-JIBLNR1 with PID 8196 (C:\LabSystem\Scheduler\target\classes started by Sitansu in C:\LabSystem\Scheduler)
2016-06-21 19:31:52.805 INFO 8196 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#bd4dc25: startup date [Tue Jun 21 19:31:52 IST 2016]; root of context hierarchy
2016-06-21 19:31:53.912 INFO 8196 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.scheduling.annotation.SchedulingConfiguration' of type [class org.springframework.scheduling.annotation.SchedulingConfiguration$$EnhancerBySpringCGLIB$$960de3bc] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-06-21 19:31:53.948 INFO 8196 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration' of type [class org.springframework.scheduling.annotation.ProxyAsyncConfiguration$$EnhancerBySpringCGLIB$$3cdcd8e2] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-06-21 19:31:54.435 INFO 8196 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2016-06-21 19:31:54.463 INFO 8196 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2016-06-21 19:31:54.560 INFO 8196 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {4.3.7.Final}
2016-06-21 19:31:54.561 INFO 8196 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2016-06-21 19:31:54.563 INFO 8196 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2016-06-21 19:31:54.900 INFO 8196 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2016-06-21 19:31:55.677 INFO 8196 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
2016-06-21 19:31:55.687 INFO 8196 --- [ main] o.h.e.jdbc.internal.LobCreatorBuilder : HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
2016-06-21 19:31:56.056 INFO 8196 --- [ main] o.h.h.i.ast.ASTQueryTranslatorFactory : HHH000397: Using ASTQueryTranslatorFactory
2016-06-21 19:31:56.592 INFO 8196 --- [ main] o.h.tool.hbm2ddl.SchemaValidator : HHH000229: Running schema validator
2016-06-21 19:31:56.593 INFO 8196 --- [ main] o.h.tool.hbm2ddl.SchemaValidator : HHH000102: Fetching database metadata
2016-06-21 19:31:56.628 INFO 8196 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000261: Table found: medxlabpro.appsettings
2016-06-21 19:31:56.629 INFO 8196 --- [ main] o.hibernate.tool.hbm2ddl.TableMetadata : HHH000037: Columns: [hl7ftphostname, hl7ftppassword, clientcode, desktopheight1, desktopheight2, newordereligipdfneeded, billingdays, receiptno, defaultpagesize, desktopheight3, postingbatchno, desktopheight4, desktopheight5, id, edibatchno, desktopheight6, datarootfolder, desktopheight7, desktopheight8, claimno, hl7ftpfolder, hl7ftpusername, neworderorderpdfneeded, authpassword, desktoppagesize8, hl7ftpport, desktoppagesize6, neworderresultpdfneeded, desktoppagesize7, desktoppagesize4, desktoppagesize5, versionno, desktoppagesize2, desktoppagesize3, desktoppagesize1, invoiceno]
2016-06-21 19:31:56.636 WARN 8196 --- [ main] s.c.a.AnnotationConfigApplicationContext : 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/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Missing column: auth_password in abcdpro.appsettings
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:961)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:950)
at org.sam.application.Application.main(Application.java:33)
Caused by: org.hibernate.HibernateException: Missing column: auth_password in abcdpro.appsettings
at org.hibernate.mapping.Table.validateColumns(Table.java:365)
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1338)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:155)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:525)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:852)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:845)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)
JPA configuration:
jpa:
generate-ddl: false
hibernate:
ddl-auto: validate
database: MYSQL
show-sql: true
How can i fix this anyone can help me please ?
Thanks
Sitansu
By default Spring Boot uses SpringNamingStrategy. This strategy generates underscores in table and field names. So for field authPassword the strategy generates auth_password column name.
If you want to map entity fields to camel case column names you can use org.hibernate.cfg.EJB3NamingStrategy or implement your own.
You can specify a naming strategy in application.properties
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
I have column in my PoJo class authpassword not auth_password.
Easy solution could be:
add #Column(name="auth_password") to your authpassword field.
Then it should work