1

I am trying to build my service as GraalVM native image using Spring and buildpacks. My application is Spring Data REST app talking to PostgreSQL database. There is nothing unusual in the code. The image builds with no issues and runs outside of Docker container, but when I am trying to run the generated GraalVM container I am getting an error:

Description:
Native reflection configuration for org.hibernate.dialect.PostgreSQLDialect is missing.

The exception is

Caused by: java.lang.ClassNotFoundException: org.hibernate.dialect.PostgreSQLDialect
    at com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:71) ~[na:na]
    at java.lang.Class.forName(DynamicHub.java:1319) ~[.....:na]
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:130) ~[na:na]

My application.yml:

---
spring:
  config:
    activate:
      on_profile: local
  datasource:
    url: jdbc:postgresql://localhost:5432/test
    username: postgres
    password: 1234
    driver-class-name: org.postgresql.Driver
  jpa:
    hibernate:
      use-new-id-generator-mappings: false
      ddl-auto: none
    show-sql: true
    properties:
      hibernate:
        dialect: org.hibernate.dialect.PostgreSQLDialect
      javax:
        persistence:
          validation:
            mode: none

I know that Spring native image support still has issues, I am just wondering if the problem is on my side.

2 Answers 2

2

There now is a way to solve this for postgres with the current version of Spring Native using version spring native hints.

Native Hints

This turns out to be simple to implement using an annotation. See example below...

package com.margic.serverless.data;

import org.hibernate.dialect.PostgreSQL95Dialect;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.nativex.hint.TypeHint;

@SpringBootApplication
@TypeHint(types = PostgreSQL95Dialect.class, typeNames = "org.hibernate.dialect.PostgreSQLDialect")
public class DataApplication {

    public static void main(String[] args) {
        SpringApplication.run(DataApplication.class, args);
    }

}
Sign up to request clarification or add additional context in comments.

Comments

0

The reason is Spring native support issues: The following dependencies are not known to work with Spring Native: ..., Rest Repositories, ...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.