Spring boot Embedded Derby not working in the latest version.

derbyspringspring-boot

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>

Best Answer

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
Related Topic