'Quarkus embedded Derby database connection not possible
We have a Quarkus application which needs to connect to an embedded derby database in order to store the application's data. The Derby DB driver in Quarkus is not able to use the provided URL to connect to the database jdbc:derby:memory:myDB and we get, at application start, the error message shown below. We encounter the same behaviour for a Derby DB persisted on files.
Our test application is a simple plain Quarkus application with the persistence configured to be an embedded Derby database (see Quarkus project setup below). We would appreciate any hint about what should be changed in the project setup, Quarkus configuration or application's code to have the Quarkus application properly connect to the Derby database.
application.properties
quarkus.datasource.db-kind=derby
quarkus.datasource.jdbc.url=jdbc:derby:memory:myDB
build.gradle (dependencies)
dependencies {
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
implementation 'io.quarkus:quarkus-arc'
implementation 'io.quarkus:quarkus-resteasy'
implementation 'io.quarkus:quarkus-hibernate-orm'
implementation 'io.quarkus:quarkus-jdbc-derby'
testImplementation 'io.quarkus:quarkus-junit5'
testImplementation 'io.rest-assured:rest-assured'
}
gradle.properties
quarkusPluginId=io.quarkus
quarkusPluginVersion=2.7.4.Final
quarkusPlatformGroupId=io.quarkus.platform
quarkusPlatformArtifactId=quarkus-bom
quarkusPlatformVersion=2.7.4.Final
Error message
WARN: Datasource '<default>': Driver does not support the provided URL: jdbc:derby:memory:myDB
März 16, 2022 1:25:13 PM org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator initiateService
WARN: HHH000342: Could not obtain connection to query metadata
java.sql.SQLException: Driver does not support the provided URL: jdbc:derby:memory:myDB
at io.agroal.pool.ConnectionFactory.connectionSetup(ConnectionFactory.java:226)
at io.agroal.pool.ConnectionFactory.createConnection(ConnectionFactory.java:210)
at io.agroal.pool.ConnectionPool$CreateConnectionTask.call(ConnectionPool.java:513)
at io.agroal.pool.ConnectionPool$CreateConnectionTask.call(ConnectionPool.java:494)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at io.agroal.pool.util.PriorityScheduledExecutor.beforeExecute(PriorityScheduledExecutor.java:75)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
Here the code of the test application
Database.java
package test;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;
/**
*
*/
@ApplicationScoped
public class Database {
@Inject
EntityManager mEntityManager;
@Transactional
public void createGift(String giftDescription) {
Gift gift = new Gift();
gift.setName(giftDescription);
mEntityManager.persist(gift);
}
}
Gift.java
package test;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
/**
*
*/
@Entity
public class Gift {
private Long id;
private String name;
@Id
@SequenceGenerator(name = "giftSeq", sequenceName = "gift_id_seq", allocationSize = 1, initialValue = 1)
@GeneratedValue(generator = "giftSeq")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
GreetingResource.java
package test;
import io.quarkus.runtime.Startup;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Startup
@Path("/hello")
public class GreetingResource {
@Inject
Database mDatabase;
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "Hello RESTEasy";
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
