6

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
Jakub Janiš
  • 131
  • 1
  • 2
  • 8

2 Answers2

16

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
Shafin Mahmud
  • 3,831
  • 1
  • 23
  • 35
-3

You don't need connection properties if you are using Spring Boot. Just add these to your POM:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derby</artifactId>
    </dependency>

Then add the usual controller, service, and repository classes.

james.garriss
  • 12,959
  • 7
  • 83
  • 96