Very slow Spring Boot application startup - spring

I have a simple Spring Boot application that connects to a PostgreSQL database and serves as a JSON service. Somehow the startup has become very slow, see timings 10:37:10 and 10:38:00:
2015-05-09 10:37:09.649 INFO 20880 --- [lication.main()] o.apache.catalina.core.StandardService : Starting service Tomcat
2015-05-09 10:37:09.651 INFO 20880 --- [lication.main()] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.20
2015-05-09 10:37:09.767 INFO 20880 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2015-05-09 10:37:09.767 INFO 20880 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2970 ms
2015-05-09 10:37:09.979 INFO 20880 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2015-05-09 10:37:09.985 INFO 20880 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2015-05-09 10:37:10.105 INFO 20880 --- [lication.main()] o.s.j.d.DriverManagerDataSource : Loaded JDBC driver: org.postgresql.Driver
2015-05-09 10:37:10.214 INFO 20880 --- [lication.main()] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2015-05-09 10:37:10.233 INFO 20880 --- [lication.main()] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2015-05-09 10:37:10.585 INFO 20880 --- [lication.main()] org.hibernate.Version : HHH000412: Hibernate Core {4.3.8.Final}
2015-05-09 10:37:10.587 INFO 20880 --- [lication.main()] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2015-05-09 10:37:10.589 INFO 20880 --- [lication.main()] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2015-05-09 10:37:10.968 INFO 20880 --- [lication.main()] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2015-05-09 10:38:00.023 INFO 20880 --- [lication.main()] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2015-05-09 10:38:00.041 INFO 20880 --- [lication.main()] o.h.e.jdbc.internal.LobCreatorBuilder : HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
2015-05-09 10:38:00.274 INFO 20880 --- [lication.main()] o.h.h.i.ast.ASTQueryTranslatorFactory : HHH000397: Using ASTQueryTranslatorFactory
Any thoughts? Is there anything I can do to diagnose the problem?

For Spring Boot you can set this in your application.properties file:
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
I also found that I needed to set another property or I would get the error "org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set". To rectify that I set this property:
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
This reduced our startup time from about 100 seconds down to 12.

Problem solved using
properties.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");
Thanks all.

Contributing application.yml version of property setting.
spring:
jpa:
properties:
hibernate:
temp:
use_jdbc_metadata_defaults: false

When I point to database in AWS RDS server it takes 78 seconds.
After given this configuration it takes 52 seconds.
spring:
jpa:
properties:
hibernate:
temp:
use_jdbc_metadata_defaults: false
And after given this configuration with the above configuration it takes only 10 seconds.
spring:
jpa:
hibernate:
ddl-auto: none

For dev environment, use the following property
spring.jpa.hibernate.ddl-auto=none
This would be a bit risky for staging and prod environment.

Are you running the tests on a local server? Perhaps there's some problem with the database server URL, such as a non-resolvable hostname or an IPv6 DNS entry, connecting with the same connection string from another application (e.g. http://squirrel-sql.sourceforge.net/) could confirm the problem.
The delay is definitely logged when creating the database connection for the first time (either while loading the driver or performing the connection).

I found the startup takes long time when the db server is far, in my case it won't take time when using the localhost db, and it take about 20 seconds in product enviroment with db is in us and server is in jp.

For springboot data JPA you need to add spring.data.jpa.repositories.bootstrap-mode=lazy in application.properties file this would also reduce bootup time.
spring.data.jpa.repositories.bootstrap-mode=lazy
spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false

I used the following piece of code
spring:
jpa:
database-platform: org.hibernate.dialect.PostgreSQLDialect
show-sql: false
generate-ddl: true
**hibernate:
ddl-auto: none
properties:
hibernate.hbm2ddl.auto: none**

Related

Not working :: spring.jpa.hibernate.ddl-auto=update

I am trying to create multitenant application with single db and seperate schemas for tenants. And I don't want to loose my data after every startup. This is my application.properties file
logging.level.root=info
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:multi-tenant
spring.jpa.hibernate.ddl-auto=update
spring.liquibase.change-log=classpath:db/changelog/changelog-master.xml
And here is my logs
Connected to the target VM, address: '127.0.0.1:53999', transport: 'socket'
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.2)
2022-08-11 13:02:28.342 INFO 25732 --- [ main] c.l.multitenant.MultiTenantApplication : Starting MultiTenantApplication using Java 18.0.1.1 on Manu with PID 25732 (D:\JAVA\multi-tenant - updated\target\classes started by itsma in D:\JAVA\multi-tenant - updated)
2022-08-11 13:02:28.342 INFO 25732 --- [ main] c.l.multitenant.MultiTenantApplication : No active profile set, falling back to 1 default profile: "default"
2022-08-11 13:02:29.534 INFO 25732 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-08-11 13:02:29.613 INFO 25732 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 53 ms. Found 1 JPA repository interfaces.
2022-08-11 13:02:30.507 INFO 25732 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-08-11 13:02:30.522 INFO 25732 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-08-11 13:02:30.522 INFO 25732 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.65]
2022-08-11 13:02:30.742 INFO 25732 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-08-11 13:02:30.742 INFO 25732 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2321 ms
2022-08-11 13:02:30.993 INFO 25732 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-08-11 13:02:31.286 INFO 25732 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-08-11 13:02:31.302 INFO 25732 --- [ main] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:multi-tenant'
2022-08-11 13:02:31.893 INFO 25732 --- [ main] liquibase.database : Set default schema name to PUBLIC
2022-08-11 13:02:32.253 INFO 25732 --- [ main] liquibase.lockservice : Successfully acquired change log lock
2022-08-11 13:02:32.929 INFO 25732 --- [ main] liquibase.changelog : Creating database history table with name: PUBLIC.DATABASECHANGELOG
2022-08-11 13:02:32.929 INFO 25732 --- [ main] liquibase.changelog : Reading from PUBLIC.DATABASECHANGELOG
Running Changeset: db/changelog/changelog-v1.0.xml::1::manu
2022-08-11 13:02:33.102 INFO 25732 --- [ main] liquibase.changelog : SQL in file db/changelog/data/data.sql executed
2022-08-11 13:02:33.102 INFO 25732 --- [ main] liquibase.changelog : ChangeSet db/changelog/changelog-v1.0.xml::1::manu ran successfully in 32ms
2022-08-11 13:02:33.117 INFO 25732 --- [ main] liquibase.lockservice : Successfully released change log lock
2022-08-11 13:02:33.321 INFO 25732 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-08-11 13:02:33.384 INFO 25732 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.10.Final
2022-08-11 13:02:33.525 INFO 25732 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-08-11 13:02:33.682 INFO 25732 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2022-08-11 13:02:34.138 INFO 25732 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-08-11 13:02:34.138 INFO 25732 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-08-11 13:02:34.530 WARN 25732 --- [ 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
2022-08-11 13:02:35.064 INFO 25732 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 1 endpoint(s) beneath base path '/actuator'
2022-08-11 13:02:35.143 INFO 25732 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-08-11 13:02:35.174 INFO 25732 --- [ main] c.l.multitenant.MultiTenantApplication : Started MultiTenantApplication in 7.407 seconds (JVM running for 8.296)
2022-08-11 13:02:37.086 INFO 25732 --- [nio-8080-exec-7] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-08-11 13:02:37.086 INFO 25732 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-08-11 13:02:37.087 INFO 25732 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
Why is ddl-auto=update not working?
You use an in memory database configuration.
This means that when the application starts up an embedded database will be created not in permanent memory but in RAM.
This also means that when the application is shut down the memory it took in RAM is cleaned, therefore any information relative with this database is also lost.
H2 database offers another configuration in the url which will make sure that the data that database holds, is not stored in RAM but in permanent storage HDD. This way the application could be shut down and the data which the database contained, will not be lost.
The database however will stop functioning when the application is shut down, as the process that runs the database belongs to the main process of starting your application. But when the application starts up again and database process is started also, the database will see all the data that it contained before the application was shutdown.
The config is the following:
spring.datasource.url= jdbc:h2:/data/multi-tenant;AUTO_SERVER=TRUE
Multiple processes can access the same database without having to
start the server manually. To do that, append ;AUTO_SERVER=TRUE to the
database URL. You can use the same database URL independent of whether
the database is already open or not. This feature doesn't work with
in-memory databases.
Use the same URL for all connections to this database. Internally,
when using this mode, the first connection to the database is made in
embedded mode, and additionally a server is started internally (as a
daemon thread). If the database is already open in another process,
the server mode is used automatically. The IP address and port of the
server are stored in the file .lock.db, that's why in-memory databases
can't be supported.
The application that opens the first connection to the database uses
the embedded mode, which is faster than the server mode. Therefore the
main application should open the database first if possible. The first
connection automatically starts a server on a random port. This server
allows remote connections, however only to this database (to ensure
that, the client reads .lock.db file and sends the random key that is
stored there to the server). When the first connection is closed, the
server stops. If other (remote) connections are still open, one of
them will then start a server (auto-reconnect is enabled
automatically).
All processes need to have access to the database files. If the first
connection is closed (the connection that started the server), open
transactions of other connections will be rolled back (this may not be
a problem if you don't disable autocommit). Explicit client/server
connections (using jdbc:h2:tcp:// or ssl://) are not supported. This
mode is not supported for in-memory databases.
H2 Documentation

Vaadin 23 Flow - Spring Boot - Live Reload not working

I recently updated my Vaadin Flow Project to the newest Version 23.0.1.
It all did great, but the LiveReload (detecting Java-FileChanges) doesnt work at all (Its detecting only CSS changes).
I created a new Spring Boot Vaadin 23 Project with Spring-Initializr to check if it's the same problem. I followed the LiveReload Section in the official Vaadin Docs, but it does'nt work at all... :(
My Console shows no errors at all..
Does someone have a similar Problem?
Console Output:
2022-03-21 12:28:33.379 INFO 16300 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
[.....]
2022-03-21 12:28:33.814 INFO 16300 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8081 (http) with context path ''
2022-03-21 12:28:33.827 INFO 16300 --- [ restartedMain] n.b.p.s.PlatonStartupApplicationListener : Initialize Application
2022-03-21 12:28:33.828 INFO 16300 --- [ restartedMain] n.b.p.s.PlatonStartupApplicationListener : Load global catalog.
2022-03-21 12:28:33.987 INFO 16300 --- [nio-8081-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-03-21 12:28:33.988 INFO 16300 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-03-21 12:28:33.992 INFO 16300 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms
2022-03-21 12:28:38.306 INFO 16300 --- [v-server-output] c.v.b.devserver.DevServerOutputTracker : [build-status] : Compiled.
←[38;5;35m
----------------- Frontend compiled successfully. -----------------
←[0m2022-03-21 12:28:38.313 INFO 16300 --- [onPool-worker-3] c.v.b.devserver.AbstractDevServerRunner : Started Webpack. Time: 9897ms
2022-03-21 12:28:38.382 INFO 16300 --- [v-server-output] c.v.b.devserver.DevServerOutputTracker : No issues found.

NullPointerException while starting Spring Shell on Heroku worker node

Recently we are facing an issue that we cannot start our Spring Shell app on our Heroku worker node anymore. Directly after the shell app has started the console just prints java.lang.NullPointerException a million times (like there is kina a loop that is trying to instantiate a bean or something which is failing all the time).
Here is an excerpt:
Running /env.sh java -jar ops.jar on ⬢ foo... up, worker.8633 (Standard-1X)
2022-03-04 07:44:37.221 INFO 5 --- [ main] ...Application : Starting Application v1.0.0-SNAPSHOT using Java 11.0.11 on 2e0b87b1-cecd-4720-8c27-4d39afba9615 with PID 5 (/ops.jar started by u27375 in /)
2022-03-04 07:44:37.226 INFO 5 --- [ main] ...Application : No active profile set, falling back to 1 default profile: "default"
2022-03-04 07:44:38.012 INFO 5 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-03-04 07:44:38.129 INFO 5 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 110 ms. Found 10 JPA repository interfaces.
2022-03-04 07:44:38.886 INFO 5 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-03-04 07:44:38.948 INFO 5 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.5.Final
2022-03-04 07:44:39.127 INFO 5 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-03-04 07:44:39.547 INFO 5 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-03-04 07:44:39.929 INFO 5 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-03-04 07:44:39.948 INFO 5 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2022-03-04 07:44:41.089 INFO 5 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-03-04 07:44:41.098 INFO 5 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-03-04 07:44:42.590 INFO 5 --- [ main] ...Application : Started Application in 5.939 seconds (JVM running for 6.39)
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
java.lang.NullPointerException
...
We use Spring Boot v2.6.4 and Spring Shell v2.0.1.RELEASE. The Spring Shell app is containerized (Docker) and we usually start it with:
heroku run --type worker -a foo -- /env.sh java -jar ops.jar
Does anyone of you guys have some tips or something on how to solve or even how to debug this further, i.e., to print the whole stacktrace of the exception?
Could this be something related to JLine in a way that in cannot be used in a Docker container together with Heroku?! However, this worked like a charm in the past.
As said, we appreciate any hint or tip on how to debug this further.
Cheers

Running Spring Boot Admin with a non-default port

I want to start the Spring Boot Admin server on a different port than 8080.
So I configured the server.port property in the bootstrap.yml file with 9000, but still the server listens on port 8080 according to the log file.
Here's my bootstrap.yml:
server:
port: 9000
spring:
application:
name: admin-server
cloud:
config:
uri: http://localhost:8888
And this is the final part of the console log:
2018-11-29 15:52:11.242 INFO 25999 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-11-29 15:52:11.271 INFO 25999 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-11-29 15:52:11.274 INFO 25999 --- [ main] n.d.d.c.a.AdminServerApplication : Started AdminServerApplication in 2.826 seconds (JVM running for 3.355)
2018-11-29 15:52:11.818 INFO 25999 --- [on(4)-127.0.0.1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-11-29 15:52:11.819 INFO 25999 --- [on(4)-127.0.0.1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2018-11-29 15:52:11.830 INFO 25999 --- [on(4)-127.0.0.1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 11 ms
In the application.properties file put this
server.port = 9000
A flashlight in my brain told me I might have forgotten to add the spring-cloud-config-client dependency, after checking, and then adding the appropriate dependency to the pom.xml, it worked like a charm:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
Thanks to all for providing feedback.
Many different configuration sources have precedence over application.properties (or YAML) as described here: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
You might need to verify if one of those sources are not interfering with the value of serve.port.

Spring boot Embedded Derby not working in the latest version.

I have used Embedded derby earlier in my spring boot projects. But now when i created the project through Spring Initializr with the derby dependency. I get the below error :
Schema 'SA' does not exist
followed by org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
When i tried running the earlier project that i had created, the Derby is working just fine.
PFB the console for the earlier project :
2018-03-18 15:34:44.346 INFO 16560 --- [ restartedMain]
org.hibernate.cfg.Environment : HHH000021: Bytecode
provider name : javassist 2018-03-18 15:34:44.391 INFO 16560 --- [
restartedMain] o.hibernate.annotations.common.Version : HCANN000001:
Hibernate Commons Annotations {5.0.1.Final} 2018-03-18 15:34:44.490
**INFO 16560 --- [ restartedMain] org.hibernate.dialect.Dialect
: HHH000400: Using dialect: org.hibernate.dialect.DerbyDialect
2018-03-18 15:34:44.497 WARN 16560 --- [ restartedMain]
org.hibernate.dialect.DerbyDialect : HHH000430: The DerbyDialect
dialect has been deprecated; use one of the version-specific dialects
** instead 2018-03-18 15:34:45.094 INFO 16560 --- [ restartedMain]
org.hibernate.tool.hbm2ddl.SchemaExport : HHH000227: Running hbm2ddl
schema export 2018-03-18 15:34:45.099 ERROR 16560 --- [
restartedMain] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000389:
Unsuccessful: drop table book 2018-03-18 15:34:45.099 ERROR 16560 ---
[ restartedMain] org.hibernate.tool.hbm2ddl.SchemaExport : Schema
'SA' does not exist 2018-03-18 15:34:45.129 WARN 16560 --- [
restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Warning
Code: 10000, SQLState: 01J01 2018-03-18 15:34:45.129 WARN 16560 --- [
restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper : Database
'memory:testdb' not created, connection made to existing database
instead. 2018-03-18 15:34:45.129 INFO 16560 --- [ restartedMain]
org.hibernate.tool.hbm2ddl.SchemaExport : HHH000230: Schema export
complete 2018-03-18 15:34:45.152 INFO 16560 --- [ restartedMain]
j.LocalContainerEntityManagerFactoryBean : Initialized JPA
EntityManagerFactory for persistence unit 'default'
The Console Log for my current spring boot with embedded derby :
2018-03-18 15:42:23.234 INFO 11312 --- [ main]
com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2018-03-18 15:42:23.237 WARN 11312 --- [ main]
**com.zaxxer.hikari.util.DriverDataSource : Registered driver with
driverClassName=org.apache.derby.jdbc.EmbeddedDriver was not found,
trying direct instantiation. 2018-03-18 15:42:23.844 INFO 11312 --- [
** main] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Driver
does not support get/set network timeout for connections. (Feature not
implemented: No details.) 2018-03-18 15:42:23.847 INFO 11312 --- [
main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start
completed. 2018-03-18 15:42:23.937 INFO 11312 --- [ main]
j.LocalContainerEntityManagerFactoryBean : Building JPA container
EntityManagerFactory for persistence unit 'default' 2018-03-18
15:42:23.969 INFO 11312 --- [ main]
o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing
PersistenceUnitInfo [ name: default ...] 2018-03-18 15:42:24.136
INFO 11312 --- [ main] org.hibernate.Version
: HHH000412: Hibernate Core {5.2.14.Final} 2018-03-18 15:42:24.138
INFO 11312 --- [ main] org.hibernate.cfg.Environment
: HHH000206: hibernate.properties not found 2018-03-18 15:42:24.199
INFO 11312 --- [ main]
o.hibernate.annotations.common.Version : HCANN000001: Hibernate
Commons Annotations {5.0.1.Final} 2018-03-18 15:42:24.380 INFO 11312
--- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.DerbyTenSevenDialect
2018-03-18 15:42:25.572 WARN 11312 --- [ main]
o.h.t.s.i.ExceptionHandlerLoggedImpl : GenerationTarget
encountered exception accepting command : Error executing DDL via JDBC
Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error
executing DDL via JDBC Statement at
org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
~[hibernate-core-5.2.14.Final.jar:5.2.14.Final] at
org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:375)
[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
The difference i can find between the two is that in the current log(abv log) it says that the
com.zaxxer.hikari.util.DriverDataSource : Registered driver with
driverClassName=org.apache.derby.jdbc.EmbeddedDriver was not found,
trying direct instantiation.
Let me know if we need to configure something apart from the below dependency for enabling this derby. Note- I dint do anything apart from maven dependency in the previous project.
Maven dependency :
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>runtime</scope>
</dependency>
Please configure you JPA Configuration as per your requirement. I've configured as below. You need to add below configuration in application.properties file.
# PROFILES
spring.profiles.active=dev
# JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database=default
spring.jpa.show-sql=true
# DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.continue-on-error=false
spring.datasource.generate-unique-name=false
add
spring.jpa.hibernate.ddl-auto=update
to your application.properties
it is by default create-drop.
The default driver used by derby is org.apache.derby.jdbc.AutoloadedDriver, but springboot and other framework choice org.apache.derby.jdbc.EmbeddedDriver.
It causes the driver to be unable to find the driver when using the datasource for the first time.
About Schema 'SA' does not exist.
I think that you use the other tool connect the derby, such as ij. And the jdbc url they use is the same. It looks like the same database connected, but it's not actually.
This is the key to the problem.
Added this in appplication.properties and worked
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database=default
spring.jpa.show-sql=true
I've added below property in application.properties, it worked!
spring.jpa.hibernate.ddl-auto=update

Resources