'org.hibernate.HibernateException: Generation of HibernateProxy instances at runtime is not allowed when the configured BytecodeProvider is 'none'

I'm working under a proxy and when i try to test my API "/auth/login" with the POST method i get this error :

enter image description here

enter image description here

2021-12-29 12:15:03.820  INFO 14556 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-12-29 12:15:03.820  INFO 14556 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2021-12-29 12:15:03.821  INFO 14556 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms
Hibernate: select personne0_.id as col_0_0_ from personne personne0_ where personne0_.identifiant=? limit ?
Hibernate: select personne0_.id as col_0_0_ from personne personne0_ where personne0_.identifiant=? limit ?
Hibernate: select personne0_.id as id1_4_, personne0_.centreid as centrei13_4_, personne0_.cin as cin2_4_, personne0_.email as email3_4_, personne0_.est_responsable as est_resp4_4_, personne0_.grade as grade5_4_, personne0_.identifiant as identifi6_4_, personne0_.matricule as matricul7_4_, personne0_.mot_de_passe as mot_de_p8_4_, personne0_.nom as nom9_4_, personne0_.prenom as prenom10_4_, personne0_.tel as tel11_4_, personne0_.ville as ville12_4_ from personne personne0_ where personne0_.identifiant=?
2021-12-29 12:15:04.349  INFO 14556 --- [nio-8080-exec-1] o.h.e.internal.DefaultLoadEventListener  : HHH000327: Error performing load command

org.hibernate.HibernateException: Generation of HibernateProxy instances at runtime is not allowed when the configured BytecodeProvider is 'none'; your model requires a more advanced BytecodeProvider to be enabled.


Solution 1:[1]

pom.xml

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-oauth2-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.experimental</groupId>
            <artifactId>spring-native</artifactId>
            <version>${spring-native.version}</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt -->
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.1.0</version>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${project.parent.version}</version>

                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                    <classifier>${repackage.classifier}</classifier>
                    <image>
                        <builder>paketobuildpacks/builder:tiny</builder>
                        <env>
                            <BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
                        </env>
                    </image>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.experimental</groupId>
                <artifactId>spring-aot-maven-plugin</artifactId>
                <version>${spring-native.version}</version>
                <executions>
                    <execution>
                        <id>test-generate</id>
                        <goals>
                            <goal>test-generate</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.hibernate.orm.tooling</groupId>
                <artifactId>hibernate-enhance-maven-plugin</artifactId>
                <version>${hibernate.version}</version>
                <executions>
                    <execution>
                        <id>enhance</id>
                        <goals>
                            <goal>enhance</goal>
                        </goals>
                        <configuration>
                            <failOnError>true</failOnError>
                            <enableLazyInitialization>true</enableLazyInitialization>
                            <enableDirtyTracking>true</enableDirtyTracking>
                            <enableAssociationManagement>true</enableAssociationManagement>
                            <enableExtendedEnhancement>false</enableExtendedEnhancement>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Personne.java

@Entity
@Data @NoArgsConstructor
@AllArgsConstructor
@ToString
public class Personne implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    private String nom;
    private String prenom;
    private long tel;
    private String ville;
    private String email;
    private String identifiant;
    private String motDePasse;
    private String grade;
    private String cin;
    private String matricule;
    private boolean estResponsable;

    public Personne(String nom, String prenom, String ville, String identifiant, String motDePasse, String grade, String cin, String matricule) {
        this.nom = nom;
        this.prenom = prenom;
        this.ville = ville;
        this.identifiant = identifiant;
        this.motDePasse = motDePasse;
        this.grade = grade;
        this.cin = cin;
        this.matricule = matricule;
    }

    @ManyToOne(fetch= FetchType.LAZY)
    @JoinColumn(name = "centreID", referencedColumnName = "id")
    private Centre centre;

    @OneToMany(mappedBy="personne", fetch= FetchType.LAZY)
    private List<Remarque> remarques = new ArrayList<Remarque>();

    @ManyToMany(fetch=FetchType.EAGER)
    @JoinTable(
            joinColumns= @JoinColumn(name="personneID"),
            inverseJoinColumns=@JoinColumn(name="roleID")
    )
    private Set<Role> roles = new HashSet<>();

}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Abdellah AITMOMIN