Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring embedded Derby in Spring Boot app

Could you please help me set up connection to the embedded Derby database in Spring Boot application?

I searched the web but can only find solutions for server-type Derby, not for embedded Derby.

spring.jpa.database = ?
spring.jpa.hibernate.ddl-auto = create-drop
like image 370
Jakub Janiš Avatar asked Jun 07 '17 11:06

Jakub Janiš


1 Answers

Derby as an in-memory database

If you want to Configure in-memory Derby database with spring boot, the minimal thing you need is to mention the runtime dependency (along with spring-boot-starter-data-jpa) as

<dependency>
    <groupId>org.apache.derby</groupId>
    <artifactId>derby</artifactId>
    <scope>runtime</scope>
</dependency>

This bare minimum configuration should work for any embedded datasource in Spring Boot. But as of current Spring Boot version (2.0.4.RELEASE) this lead to an error only for Derby

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing
DDL via JDBC Statement
Caused by: java.sql.SQLSyntaxErrorException: Schema 'SA' does not exist

This happens because of default configuration ofspring.jpa.hibernate.ddl-auto=create-drop see this spring-boot issue for details.

So you need to override that property in your application.properties as

spring.jpa.hibernate.ddl-auto=update

Derby as a persistent database

If you want to use Derby as your persistent database. Add these application properties

spring.datasource.url=jdbc:derby:mydb;create=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.DerbyTenSevenDialect
spring.jpa.hibernate.ddl-auto=update
like image 99
Shafin Mahmud Avatar answered Sep 22 '22 23:09

Shafin Mahmud