Skip to content

Database issue with spring boot 3.2.0 and native image: not a managed type

Notifications You must be signed in to change notification settings

DigitalMediageek/aot-database-issue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

native-multiple-databases

1. Introduction

This sample project show how to use multiple database with spring boot and get it running with native images, successfully.

1.1 Requirements

Uses Spring Boot 3.2.0 and GraalVM 21. Uses PostgreSQL DB on localhost. Adopt database to your needs.

Spring Boot 3.2.0 was choosen on purpose, because

1.2 Usage

Compile with mvn -Pnative native:compile. Run by executing native platform binary from directory target.

After application has been started it will create an entry in table mydata of both databases by processing code in DatabaseApplication which is annotated with @PostConstruct.

2. Database setup

Two datasources are configured in application.yaml:

graal1:
  datasource:
    jdbcUrl: jdbc:postgresql://localhost:5432/graal
    driverClassName: org.postgresql.Driver
    username: postgres
    password: postgres
graal2:
  datasource:
    jdbcUrl: jdbc:postgresql://localhost:5432/graal2
    driverClassName: org.postgresql.Driver
    username: postgres
    password: postgres

Pay attention to parameter @Qualifier("graalPMT")PersistenceManagedTypes persistenceManagedTypes of LocalContainerEntityManagerFactoryBean in database configurations. This is required to prevent Not a managed type exception message, heavily documented on StackOverflow when running as a native app.

Spring documentation about it can be found here: https://docs.spring.io/spring-framework/reference/core/aot.html#aot.bestpractices.jpa

About

Database issue with spring boot 3.2.0 and native image: not a managed type

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages