vladmihalcea / hypersistence-optimizer

Hypersistence Optimizer allows you to get the most out of JPA and Hibernate. By scanning your application configuration and mappings, Hypersistence Optimizer can tell you what changes you need to do to speed up your data access layer.
https://vladmihalcea.com/hypersistence-optimizer/
Apache License 2.0
318 stars 43 forks source link

EntityManagerFactory Incompatibility with Spring Boot 3.3 and Hypersistence Optimizer #249

Closed rgordeev closed 2 months ago

rgordeev commented 2 months ago

Description: I am using Spring Boot 3.3 in my project, which uses the jakarta.persistence package as part of its Jakarta EE 9+ compliance. However, the hypersistence-optimizer library includes code that references javax.persistence.EntityManagerFactory instead of jakarta.persistence.EntityManagerFactory.

This causes a compilation error in my project, as Spring Boot 3.3 and Hibernate 6.x rely on the Jakarta EE API (jakarta.persistence) rather than the javax.persistence API, which is now outdated in modern versions of Spring Boot.

Here is the error message:

Hibernate compile-time tooling 6.5.2.Final
../config/HypersistenceConfiguration.java:16: error: cannot access EntityManagerFactory
        new JpaConfig(entityManagerFactory)
        ^
  class file for javax.persistence.EntityManagerFactory not found

Problem Code: The JpaConfig class in hypersistence-optimizer is currently written as:

package io.hypersistence.optimizer.core.config;

import javax.persistence.EntityManagerFactory;

public final class JpaConfig extends Config {
    private final EntityManagerFactory entityManagerFactory;

    public JpaConfig(EntityManagerFactory entityManagerFactory) {
        this.entityManagerFactory = entityManagerFactory;
    }

    public EntityManagerFactory getEntityManagerFactory() {
        return this.entityManagerFactory;
    }
}

Proposed Solution: To maintain compatibility with modern Spring Boot and Hibernate versions (e.g., Spring Boot 3.3 and Hibernate 6.x), the javax.persistence imports should be updated to jakarta.persistence:

import jakarta.persistence.EntityManagerFactory;

Environment:

vladmihalcea commented 2 months ago

As explained in the Installation Guide, you need to use the jakarta classifier:

<dependency>
    <groupid>io.hypersistence</groupid>
    <artifactid>hypersistence-optimizer</artifactid>
    <version>2.10.0</version>
    <classifier>jakarta</classifier>
</dependency>