Platform.sh User Documentation

How to Deploy Quarkus on Platform.sh with JPA

Try for 30 days
Flexible, version-controlled infrastructure provisioning and development-to-production workflows
Activate your trial

Hibernate ORM is a standard JPA implementation. It offers you the full breadth of an Object Relational Mapper and it works well in Quarkus. To activate JPA and then have it accessed by the Quarkus application already configured for Platform.sh, it is necessary to modify two files.

1. Add a SQL database service Anchor to this heading

In your service configuration, include a SQL database service. Make sure to visit the documentation for that service to find a valid version. For PostgreSQL that would look like:

.platform/services.yaml
postgresql:
    type: postgresql:16
    disk: 256

2. Grant access to the service through a relationship Anchor to this heading

To access the new service, set a relationship in your app configuration.

.platform.app.yaml
relationships:
    postgresql: "postgresql:postgresql"

3. Export connection credentials to the environment Anchor to this heading

Connection credentials for services are exposed to the application container through the PLATFORM_RELATIONSHIPS environment variable from the deploy hook onward. Since this variable is a base64 encoded JSON object of all of your project’s services, you’ll likely want a clean way to extract the information specific to the database into it’s own environment variables that can be used by Quarkus. On Platform.sh, custom environment variables can be defined programmatically in a .environment file using jq to do just that:

export HOST=$(echo $PLATFORM_RELATIONSHIPS | base64 --decode | jq -r ".postgresdatabase[0].host")
export DATABASE=$(echo $PLATFORM_RELATIONSHIPS | base64 --decode | jq -r ".postgresdatabase[0].path")
export QUARKUS_DATASOURCE_PASSWORD=$(echo $PLATFORM_RELATIONSHIPS | base64 --decode | jq -r ".postgresdatabase[0].password")
export QUARKUS_DATASOURCE_USERNAME=$(echo $PLATFORM_RELATIONSHIPS | base64 --decode | jq -r ".postgresdatabase[0].username")
export QUARKUS_DATASOURCE_JDBC_URL=jdbc:postgresql://${HOST}/${DATABASE}
export QUARKUS_HTTP_PORT=$PORT
export JAVA_OPTS="-Xmx$(jq .info.limits.memory /run/config.json)m -XX:+ExitOnOutOfMemoryError"

4. Connect to the service Anchor to this heading

Commit that code and push. The specified cluster will now always point to the PostgreSQL or any SQL service that you wish.

Is this page helpful?