Spring Boot Multiple Datasources set autocommit to false for all - spring-boot

I have two datasources in a Spring Boot application. I want to set the autocommit to false, however it's only setting one connection to false, at least per the logging the logging for the Hikari connection pool. Somehow Spring takes the datasource wraps it into this Hikari connection but leaves me scratching my head as to which one it did that for.
I'd like to know how, in my application.properties file, I can set the autocommit to all of my datasources. Bonus points to tell me how to name the connection pool that the datasource gets wrapped into.
Below is the application.properties:
spring.datasource.url=${BLUECOST_DATASOURCE_URL}
spring.datasource.username=${BLUECOST_DATASOURCE_USERNAME}
spring.datasource.password=${BLUECOST_DATASOURCE_PASSWORD}
spring.datasource.driver-class-name=${BLUECOST_DATASOURCE_DRIVER}
spring.datasource.auto-commit=false
spring.batch-datasource.url=${BATCH_DATASOURCE_URL}
spring.batch-datasource.username=${BATCH_DATASOURCE_USERNAME}
spring.batch-datasource.password=${BATCH_DATASOURCE_PASSWORD}
spring.batch-datasource.driver-class-name=${BATCH_DATASOURCE_DRIVER}
spring.batch-datasource.jpa
spring.batch-datasource.auto-commit=false
spring.jpa.database-platform=DB2
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.DB2Dialect
spring.jpa.properties.hibernate.default_schema=${cost.rules.schema}
Logging snippet:
2021-09-11 23:38:07,431 INFO [https-jsse-nio-8448-exec-7]: com.ibm.cio.sprint.cost.rules.resource.SoftLayerController Received getAsyncUploadSoftLayerFile request job instance id=33 job execution id=33
2021-09-11 23:38:07,432 INFO [https-jsse-nio-8448-exec-7]: com.ibm.cio.sprint.cost.rules.application.SoftLayerJobService Looking for status of job instance id 33 job execution id
2021-09-11 23:38:07,432 DEBUG [https-jsse-nio-8448-exec-7]: org.springframework.jdbc.core.JdbcTemplate Executing prepared SQL query
2021-09-11 23:38:07,433 DEBUG [https-jsse-nio-8448-exec-7]: org.springframework.jdbc.core.JdbcTemplate Executing prepared SQL statement [SELECT JOB_INSTANCE_ID, JOB_NAME, JOB_KEY, VERSION from BLUECOST.BATCH_JOB_INSTANCE where JOB_INSTANCE_ID = ?]
2021-09-11 23:38:07,433 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig HikariPool-2 - configuration:
2021-09-11 23:38:07,434 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig allowPoolSuspension.............false
2021-09-11 23:38:07,435 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig autoCommit......................true
2021-09-11 23:38:07,435 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig catalog.........................none
2021-09-11 23:38:07,435 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig connectionInitSql...............none
2021-09-11 23:38:07,435 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig connectionTestQuery.............none
2021-09-11 23:38:07,436 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig connectionTimeout...............30000
2021-09-11 23:38:07,436 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig dataSource......................none
2021-09-11 23:38:07,436 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig dataSourceClassName.............none
2021-09-11 23:38:07,437 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig dataSourceJNDI..................none
2021-09-11 23:38:07,437 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig dataSourceProperties............{password=<masked>}
2021-09-11 23:38:07,437 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig driverClassName................."com.ibm.db2.jcc.DB2Driver"
2021-09-11 23:38:07,437 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig healthCheckProperties...........{}
2021-09-11 23:38:07,438 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig healthCheckRegistry.............none
2021-09-11 23:38:07,438 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig idleTimeout.....................600000
2021-09-11 23:38:07,438 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig initializationFailTimeout.......1
2021-09-11 23:38:07,439 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig isolateInternalQueries..........false
2021-09-11 23:38:07,439 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig jdbcUrl.........................jdbc:db2://<omitted>;
2021-09-11 23:38:07,440 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig leakDetectionThreshold..........0
2021-09-11 23:38:07,440 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig maxLifetime.....................1800000
2021-09-11 23:38:07,440 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig maximumPoolSize.................10
2021-09-11 23:38:07,441 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig metricRegistry..................none
2021-09-11 23:38:07,441 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig metricsTrackerFactory...........none
2021-09-11 23:38:07,442 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig minimumIdle.....................10
2021-09-11 23:38:07,442 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig password........................<masked>
2021-09-11 23:38:07,443 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig poolName........................"HikariPool-2"
2021-09-11 23:38:07,443 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig readOnly........................false
2021-09-11 23:38:07,444 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig registerMbeans..................false
2021-09-11 23:38:07,444 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig scheduledExecutor...............none
2021-09-11 23:38:07,445 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig schema..........................none
2021-09-11 23:38:07,445 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig threadFactory...................internal
2021-09-11 23:38:07,445 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig transactionIsolation............default
2021-09-11 23:38:07,446 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig username........................"90529100"
2021-09-11 23:38:07,446 DEBUG [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariConfig validationTimeout...............5000
2021-09-11 23:38:07,446 INFO [https-jsse-nio-8448-exec-7]: com.zaxxer.hikari.HikariDataSource HikariPool-2 - Starting...
I tried setting default-auto-commit to false, but Hikari still built an autocommit to true
I looked on SO at question:
Spring Boot 2 disable Autocommit Hikari with multiple datasources, and I tried some of the suggestions mentioned, except this one:
"...long story short make sure that you add .type(HikariDataSource.class) before you build your class." I don't know what they meant by that. Is that some application.properties change or some Spring annotation change?
Thanks,
Woodsman

Related

Hilla not starting Vite - what am I missing?

I have created a hilla app using this:
npx #vaadin/cli init --hilla --auth hilla-with-auth
Works fine!
Now I am trying to add that to an existing spring boot application, but I am having issues with Vite not starting as it should. No exception. No help in the debug output.
I have added:
relevant files in the root (package.json, vite.config.ts, etc.)
vaadin-featureflags.properties in resources folder
hilla dependencies in pom.xml as well as the build plugin
hill annotations to my application class (#Theme, #PWA) and made it extends SpringBootServletInitializer implements AppShellConfigurator
But even if everything seems to be initialized correctly, Vite does not start. Can anyone guide me in the right direction?
This is the most relevant output log:
2022-06-07 08:04:54.046 DEBUG 4947 --- [restartedMain] c.v.f.s.f.s.FullDependenciesScanner :
List of npm dependencies found in the project:
- #hilla/form 1.0.1 dev.hilla.EndpointController
....
2022-06-07 08:04:54.057 DEBUG 4947 --- [restartedMain] c.v.f.s.f.TaskGeneratePackageJson : writing file /Users/michael/Development/Previsto/previsto-server/target/flow-frontend/package.json.
2022-06-07 08:05:02.102 INFO 4947 --- [restartedMain] o.a.container.JSR356AsyncSupport : JSR 356 Mapping path /vaadinServlet
2022-06-07 08:05:02.176 INFO 4947 --- [restartedMain] c.v.f.s.DefaultDeploymentConfiguration :
Vaadin is running in DEBUG MODE.
When deploying application for production, remember to disable debug features. See more from https://vaadin.com/docs/
The following EXPERIMENTAL features are enabled:
- Use Vite for faster front-end builds
2022-06-07 08:05:02.207 DEBUG 4947 --- [restartedMain] c.v.f.s.c.PushRequestHandler : Using pre-initialized Atmosphere for servlet springServlet
2022-06-07 08:05:02.210 DEBUG 4947 --- [restartedMain] c.v.flow.server.VaadinServletService : Using 'com.vaadin.flow.server.communication.IndexHtmlRequestHandler' in client mode bootstrapping
2022-06-07 08:05:02.212 DEBUG 4947 --- [restartedMain] com.vaadin.flow.server.VaadinService : The application has the following routes:
2022-06-07 08:05:02.956 INFO 4947 --- [restartedMain] c.v.flow.server.frontend.FrontendTools : Project node version 16.10.0 is older than 16.14.0. Using node from /Users/michael/.vaadin.
2022-06-07 08:05:03.404 DEBUG 4947 --- [http-nio-8080-exec-1] c.v.f.s.s.VaadinDefaultRequestCache : Saving request to /
2022-06-07 08:05:03.471 DEBUG 4947 --- [http-nio-8080-exec-2] c.v.b.devserver.AbstractDevServerRunner : Requesting resource from Vite http://localhost:0/login
2022-06-07 08:05:03.486 ERROR 4947 --- [http-nio-8080-exec-2] o.a.c.c.C.[.[.[/].[springServlet] : Servlet.service() for servlet [springServlet] threw exception
java.net.ConnectException: Can't assign requested address (connect failed)
at ...

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.

HikariCP shows unavailable connections while database has no sessions running - how to find the cause?

I have an application running with Spring-Boot using Spring's default Hikari Connection Pool.
Recently the server started having issues with unavailable connections:
DEBUG HikariPool (411) - HikariPool-1 - Pool stats (total=20, active=20, idle=0, waiting=3)
DEBUG HikariPool (411) - HikariPool-1 - Timeout failure stats (total=20, active=20, idle=0, waiting=2)
WARN SqlExceptionHelper(137) - SQL Error: 0, SQLState: null
ERROR SqlExceptionHelper(142) - HikariPool-1 - Connection is not available, request timed out after 30005ms.
Since it is a shared database, first I wasn't sure if it is a problem in my application. But after restarting the application the connection was fine again, so I now need to find the cause. The error occurs only on the productive system which is used all around the clock with many actions per minute. I tried to figure out what was causing rising active connections in Hikari by scanning the logs for specific statements executed before the rising connection - but there were always different or unclear actions.
So then we executed a script on the database to return all active connections (gv$session). The result returned not a single active session even though the Hikari Logs showed active connections at the same time. Can anybody tell me what this means and/or has a clue where to find the root cause of this issue?
I use Spring Boot v2.1.4.
These are my hikari settings: (default with spring.datasource.hikari.maximum-pool-size=20)
DEBUG HikariConfig (1020) - HikariPool-1 - configuration:
DEBUG HikariConfig (1052) - allowPoolSuspension.............false
DEBUG HikariConfig (1052) - autoCommit......................true
DEBUG HikariConfig (1052) - catalog.........................none
DEBUG HikariConfig (1052) - connectionInitSql...............none
DEBUG HikariConfig (1052) - connectionTestQuery.............none
DEBUG HikariConfig (1052) - connectionTimeout...............30000
DEBUG HikariConfig (1052) - dataSource......................none
DEBUG HikariConfig (1052) - dataSourceClassName.............none
DEBUG HikariConfig (1052) - dataSourceJNDI..................none
DEBUG HikariConfig (1052) - dataSourceProperties............{password=<masked>}
DEBUG HikariConfig (1052) - driverClassName................."oracle.jdbc.OracleDriver"
DEBUG HikariConfig (1052) - healthCheckProperties...........{}
DEBUG HikariConfig (1052) - healthCheckRegistry.............none
DEBUG HikariConfig (1052) - idleTimeout.....................600000
DEBUG HikariConfig (1052) - initializationFailTimeout.......1
DEBUG HikariConfig (1052) - isolateInternalQueries..........false
DEBUG HikariConfig (1052) - jdbcUrl.........................jdbc:oracle:thin:<masked>
DEBUG HikariConfig (1052) - leakDetectionThreshold..........0
DEBUG HikariConfig (1052) - maxLifetime.....................1800000
DEBUG HikariConfig (1052) - maximumPoolSize.................20
DEBUG HikariConfig (1052) - metricRegistry..................none
DEBUG HikariConfig (1052) - metricsTrackerFactory...........none
DEBUG HikariConfig (1052) - minimumIdle.....................20
DEBUG HikariConfig (1052) - password........................<masked>
DEBUG HikariConfig (1052) - poolName........................"HikariPool-1"
DEBUG HikariConfig (1052) - readOnly........................false
DEBUG HikariConfig (1052) - registerMbeans..................false
DEBUG HikariConfig (1052) - scheduledExecutor...............none
DEBUG HikariConfig (1052) - schema..........................none
DEBUG HikariConfig (1052) - threadFactory...................internal
DEBUG HikariConfig (1052) - transactionIsolation............default
DEBUG HikariConfig (1052) - username........................none
DEBUG HikariConfig (1052) - validationTimeout...............5000
Enable leakDetectionThreshold=<max query time in ms> (documented here).
It logs connections not returned to the pool within the time specified.

Limit jdbc connection pool fixed amount

Hi i use micronaut data together with various jdbc connection pools.
I first had hikari and also tried the tomcat one.
What i was assuming that setting the datasource to maximum-pool-size: 10 results in max 10 open connections.
But it seems that there is a lot of opening and closing going on. Together with a lot o requests at the same time, it uses much more than only 10 connections. The thing is, that the azure postgresql only allows 100 connections in total.
Currently i have running 7 apps accessing that database. Which i expect to result in 70 connections max total. But in reality it is much more.
I also tried using the tomcat jdbc pool, he behaves a little differntly. But also uses more than the 10 connections. I also checked using a java profiler and figured out, that some times its up to 100 open/close connection events per second.
Any suggestion how to act in that case, except of using a second database.
I was hoping that the pool will buffer the calls, especially cause they come from a kafka topic.
But well, seems to be differently.
--- edit add hikari log
Here is the log output of hikari
2020-12-11 11:59:40,983 [main] DEBUG com.zaxxer.hikari.HikariConfig - Driver class org.postgresql.Driver found in Thread context class loader jdk.internal.loader.ClassLoaders$AppClassLoader#2c13da15
2020-12-11 11:59:40,993 [main] DEBUG com.zaxxer.hikari.HikariConfig - HikariPool-1 - configuration:
2020-12-11 11:59:40,999 [main] DEBUG com.zaxxer.hikari.HikariConfig - allowPoolSuspension.............false
2020-12-11 11:59:41,000 [main] DEBUG com.zaxxer.hikari.HikariConfig - autoCommit......................true
2020-12-11 11:59:41,000 [main] DEBUG com.zaxxer.hikari.HikariConfig - catalog.........................none
2020-12-11 11:59:41,001 [main] DEBUG com.zaxxer.hikari.HikariConfig - connectionInitSql...............none
2020-12-11 11:59:41,001 [main] DEBUG com.zaxxer.hikari.HikariConfig - connectionTestQuery............."SELECT 1;"
2020-12-11 11:59:41,001 [main] DEBUG com.zaxxer.hikari.HikariConfig - connectionTimeout...............30000
2020-12-11 11:59:41,002 [main] DEBUG com.zaxxer.hikari.HikariConfig - dataSource......................none
2020-12-11 11:59:41,002 [main] DEBUG com.zaxxer.hikari.HikariConfig - dataSourceClassName.............none
2020-12-11 11:59:41,002 [main] DEBUG com.zaxxer.hikari.HikariConfig - dataSourceJNDI..................none
2020-12-11 11:59:41,003 [main] DEBUG com.zaxxer.hikari.HikariConfig - dataSourceProperties............{password=<masked>}
2020-12-11 11:59:41,004 [main] DEBUG com.zaxxer.hikari.HikariConfig - driverClassName................."org.postgresql.Driver"
2020-12-11 11:59:41,004 [main] DEBUG com.zaxxer.hikari.HikariConfig - exceptionOverrideClassName......none
2020-12-11 11:59:41,004 [main] DEBUG com.zaxxer.hikari.HikariConfig - healthCheckProperties...........{}
2020-12-11 11:59:41,005 [main] DEBUG com.zaxxer.hikari.HikariConfig - healthCheckRegistry.............none
2020-12-11 11:59:41,005 [main] DEBUG com.zaxxer.hikari.HikariConfig - idleTimeout.....................600000
2020-12-11 11:59:41,005 [main] DEBUG com.zaxxer.hikari.HikariConfig - initializationFailTimeout.......1
2020-12-11 11:59:41,006 [main] DEBUG com.zaxxer.hikari.HikariConfig - isolateInternalQueries..........false
2020-12-11 11:59:41,007 [main] DEBUG com.zaxxer.hikari.HikariConfig - jdbcUrl.........................jdbc:postgresql://URL:5432/postgres
2020-12-11 11:59:41,007 [main] DEBUG com.zaxxer.hikari.HikariConfig - leakDetectionThreshold..........0
2020-12-11 11:59:41,007 [main] DEBUG com.zaxxer.hikari.HikariConfig - maxLifetime.....................1800000
2020-12-11 11:59:41,008 [main] DEBUG com.zaxxer.hikari.HikariConfig - maximumPoolSize.................10
2020-12-11 11:59:41,008 [main] DEBUG com.zaxxer.hikari.HikariConfig - metricRegistry..................none
2020-12-11 11:59:41,008 [main] DEBUG com.zaxxer.hikari.HikariConfig - metricsTrackerFactory...........none
2020-12-11 11:59:41,009 [main] DEBUG com.zaxxer.hikari.HikariConfig - minimumIdle.....................10
2020-12-11 11:59:41,009 [main] DEBUG com.zaxxer.hikari.HikariConfig - password........................<masked>
2020-12-11 11:59:41,009 [main] DEBUG com.zaxxer.hikari.HikariConfig - poolName........................"HikariPool-1"
2020-12-11 11:59:41,010 [main] DEBUG com.zaxxer.hikari.HikariConfig - readOnly........................false
2020-12-11 11:59:41,010 [main] DEBUG com.zaxxer.hikari.HikariConfig - registerMbeans..................false
2020-12-11 11:59:41,011 [main] DEBUG com.zaxxer.hikari.HikariConfig - scheduledExecutor...............none
2020-12-11 11:59:41,011 [main] DEBUG com.zaxxer.hikari.HikariConfig - schema.........................."SCHEMA"
2020-12-11 11:59:41,011 [main] DEBUG com.zaxxer.hikari.HikariConfig - threadFactory...................internal
2020-12-11 11:59:41,011 [main] DEBUG com.zaxxer.hikari.HikariConfig - transactionIsolation............default
2020-12-11 11:59:41,012 [main] DEBUG com.zaxxer.hikari.HikariConfig - username........................"USERNAME"
2020-12-11 11:59:41,012 [main] DEBUG com.zaxxer.hikari.HikariConfig - validationTimeout...............5000
I found the mistake - or at least something that solves the issue.
While saving some data into the database i also try to update the cache.
But due to change on caffeines loadingcache, each save also results in a get on the exactly same data object instance.
My guessing is due the transaction that causes trouble.
After replacing the cache.get with the cache.replace everything works fine.

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