Spring boot 3, javax.persistence and entity scan

136 views Asked by At

I know there are lots of questions and discussions about spring boot migration from 2.7 to 3.x, but I was not able to find an answer on my (specific) problem.

I have a plugin that is needed by 2 different spring boot rest api applications, one is using boot 2.7.8 (written in java, not migrated yet) and one using boot 3.1.8 (written in kotlin).
This plugin defines 2 JPA entities, annotated with javax.persistence.Entity and compiled with spring boot 2.7.8 and java version 17.

When I run the 3.1.8 spring boot app, I get the error "java.lang.IllegalArgumentException: Not a managed type", since the org.springframework.boot.autoconfigure.domain.EntityScan only loads entities defined with jakarta.persistence.Entity annotation ?

Is there a way to make spring boot 3.x load old javax.persistence.Entity entities ? (until we migrate the 2.7.8 app to 3.x and then we can also migrate the plugin in question to java 17...)

The only solution I see now is to fork the plugin, have 1 version remain with javax. and one version with jakarta. and any future changes be done in both versions ...

fragments from pom.xml of the 3.1.8 app

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.1.8</version>
</parent>
<properties>
    <java.version>17</java.version>
    <kotlin.version>1.9.10</kotlin.version>
</properties>
<dependencies>
  <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.1</version>
    <scope>provided</scope>
  </dependency>
  <dependency>
    <groupId>javax.persistence</groupId>
    <artifactId>javax.persistence-api</artifactId>
    <version>2.2</version>
  </dependency>
  <dependency>
    <groupId>javax.transaction</groupId>
    <artifactId>javax.transaction-api</artifactId>
    <version>1.2</version>
  </dependency>
  <dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>2.0.1.Final</version>
  </dependency>
<dependencies>

3.1.8 App (written in Kotlin)

@SpringBootApplication
@ConfigurationPropertiesScan
@EnableJpaRepositories(basePackages = ["com.server.repository", "com.plugin.dao"])
@EntityScan(basePackages = ["com.server.entity", "com.plugin.model"])
class MyServerApplication

Entity from plugin (written in Java)

package com.plugin.model;

import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name = "error_log")
public class ErrorLog {...}
0

There are 0 answers