Error with Jakarta in spring boot 3.1.0 the project does not compile

546 views Asked by At

Greeting, someone can help me with an error in a spring boot application version 3.1.0 that use jakarta. Before using a Jakarta dependency, the project compiled for me, but after adding the dependency implementation group: 'jakarta.platform', name: 'jakarta.jakartaee-api', version: '9.1.0'

The project does not compile and I get this error

2023-10-18T00:19:11.408-05:00 ERROR 36064 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: UUID
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1770) ~[spring-beans-6.0.9.jar:6.0.9]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598) ~[spring-beans-6.0.9.jar:6.0.9]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520) ~[spring-beans-6.0.9.jar:6.0.9]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[spring-beans-6.0.9.jar:6.0.9]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.0.9.jar:6.0.9]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[spring-beans-6.0.9.jar:6.0.9]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.0.9.jar:6.0.9]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1156) ~[spring-context-6.0.9.jar:6.0.9]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:931) ~[spring-context-6.0.9.jar:6.0.9]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:608) ~[spring-context-6.0.9.jar:6.0.9]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.1.0.jar:3.1.0]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:733) ~[spring-boot-3.1.0.jar:3.1.0]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:435) ~[spring-boot-3.1.0.jar:3.1.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) ~[spring-boot-3.1.0.jar:3.1.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1305) ~[spring-boot-3.1.0.jar:3.1.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1294) ~[spring-boot-3.1.0.jar:3.1.0]
    at com.co.loteriademedellin.lotterpmixturesvc.core.LotterpMixtureSvcApplication.main(LotterpMixtureSvcApplication.java:9) ~[main/:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-3.1.0.jar:3.1.0]
Caused by: java.lang.NoSuchFieldError: UUID
    at org.hibernate.id.factory.internal.StandardIdentifierGeneratorFactory.registerJpaGenerators(StandardIdentifierGeneratorFactory.java:111) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
    at org.hibernate.id.factory.internal.StandardIdentifierGeneratorFactory.<init>(StandardIdentifierGeneratorFactory.java:86) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
    at org.hibernate.id.factory.internal.StandardIdentifierGeneratorFactory.<init>(StandardIdentifierGeneratorFactory.java:77) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
    at org.hibernate.id.factory.internal.StandardIdentifierGeneratorFactoryInitiator.initiateService(StandardIdentifierGeneratorFactoryInitiator.java:25) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
    at org.hibernate.id.factory.internal.StandardIdentifierGeneratorFactoryInitiator.initiateService(StandardIdentifierGeneratorFactoryInitiator.java:15) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:119) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:264) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:239) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:216) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
    at org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl.<init>(MetadataBuilderImpl.java:624) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
    at org.hibernate.boot.internal.MetadataBuilderImpl.<init>(MetadataBuilderImpl.java:140) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
    at org.hibernate.boot.MetadataSources.getMetadataBuilder(MetadataSources.java:163) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:269) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:190) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-6.0.9.jar:6.0.9]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:376) ~[spring-orm-6.0.9.jar:6.0.9]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) ~[spring-orm-6.0.9.jar:6.0.9]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) ~[spring-orm-6.0.9.jar:6.0.9]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:352) ~[spring-orm-6.0.9.jar:6.0.9]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1816) ~[spring-beans-6.0.9.jar:6.0.9]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1766) ~[spring-beans-6.0.9.jar:6.0.9]
    ... 21 common frames omitted

this is the build.gradle


buildscript {
    ext {
        set("springBootVersion", '3.1.0')
        set("springCloudVersion", '2022.0.3')
        set("springDependencyManagementVersion", '1.1.0')
        set("jakarta-servlet.version", '5.0.0')
    }

    repositories {
        mavenCentral()
    }

    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
        classpath "io.spring.gradle:dependency-management-plugin:${springDependencyManagementVersion}"
    }
}

plugins {
    id 'java'
    id 'org.springframework.boot' version "${springBootVersion}"
    id 'io.spring.dependency-management' version "${springDependencyManagementVersion}"
}

allprojects {
    apply plugin: 'java'
    apply plugin: 'application'
    apply plugin: 'eclipse'
    apply plugin: 'idea'
    apply plugin: 'io.spring.dependency-management'
    apply plugin: 'org.springframework.boot'

    java {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

    compileJava.options.encoding = 'UTF-8'

    configurations {
        compileOnly {
            extendsFrom annotationProcessor
        }
    }

    repositories {
        mavenCentral()

    }


    configurations {
        compileOnly {
            extendsFrom annotationProcessor
        }
    }

    repositories {
        mavenCentral()
    }

    dependencies {
        implementation('org.springframework.boot:spring-boot-starter-web') {
            exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
        }
        implementation 'org.springframework.boot:spring-boot-starter-actuator'
        implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
        implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
        implementation 'org.springframework.boot:spring-boot-starter-validation'
        implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap'
        implementation 'org.springframework.cloud:spring-cloud-starter-config'
        implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
        implementation 'org.springframework.cloud:spring-cloud-starter-circuitbreaker-resilience4j'
        implementation platform('com.amazonaws:aws-java-sdk-bom:1.12.494')
        implementation 'com.amazonaws:aws-java-sdk-core'
        implementation 'software.amazon.msk:aws-msk-iam-auth:1.1.7'
        compileOnly 'org.projectlombok:lombok'
        developmentOnly 'org.springframework.boot:spring-boot-devtools'
        runtimeOnly 'com.oracle.database.jdbc:ojdbc8'
        annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
        annotationProcessor 'org.projectlombok:lombok'
        testImplementation 'org.springframework.boot:spring-boot-starter-test'
        implementation 'org.apache.commons:commons-compress:1.22'
        implementation group: 'org.apache.poi', name: 'poi', version: '5.2.2'
        implementation group: 'org.apache.poi', name: 'poi-ooxml', version: '4.1.1'
        implementation 'org.apache.commons:commons-lang3:3.12.0'
        implementation group: 'jakarta.platform', name: 'jakarta.jakartaee-api', version: '9.1.0'

    }

    dependencyManagement {
        imports {
            mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
        }
    }

    tasks.named('test') {
        useJUnitPlatform()
    }
}


I am trying to create a service to generate an excel file

package com.co.loteriademedellin.lotterpmixturesvc.common.generator;


import com.co.loteriademedellin.lotterpmixturesvc.common.response.GenerateComponentExcelResponse;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.OutputStream;
import java.sql.Timestamp;
import java.util.List;
@Slf4j
public class ComponentExcelGenerator {

    private final List<List<GenerateComponentExcelResponse>> rows;
    private final OutputStream outputStream;
    private final String reportName;

    public ComponentExcelGenerator(List<List<GenerateComponentExcelResponse>> rows, OutputStream outputStream, String reportName) {
        this.rows = rows;
        this.outputStream = outputStream;
        this.reportName = reportName;
    }

    private void createCell(SXSSFSheet sheet, Row row, int columnCount, Object value, CellStyle style){
        Cell cell = row.createCell(columnCount);
        if (value instanceof Integer) {
            cell.setCellValue((Integer) value);
        } else if (value instanceof Long) {
            cell.setCellValue((Long) value);
        } else if (value instanceof Boolean) {
            cell.setCellValue((Boolean) value);
        } else if (value instanceof Double) {
            cell.setCellValue((Double) value);
        } else if (value instanceof Timestamp) {
            cell.setCellValue((Timestamp) value);
        } else {
            cell.setCellValue((String) value);
        }
        cell.setCellStyle(style);
    }

    private void writeHeaderLine(SXSSFWorkbook workbook, SXSSFSheet sheet){
        Row row = sheet.createRow(1);
        Row tittleRow = sheet.createRow(0);

        CellStyle style = workbook.createCellStyle();
        CellStyle tittleStyle = workbook.createCellStyle();

        Font font = workbook.createFont();
        font.setFontHeightInPoints((short) 16);
        font.setBold(true);

        Font tittleFont = workbook.createFont();
        tittleFont.setFontHeightInPoints((short) 16);
        tittleFont.setBold(true);


        style.setFont(font);
        tittleStyle.setFont(tittleFont);

        sheet.setAutoFilter(new CellRangeAddress(1, 1, 0, 21));
        tittleStyle.setAlignment(HorizontalAlignment.CENTER);

        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 22));

        createCell(sheet, tittleRow, 0, reportName, tittleStyle);
        createCell(sheet, row, 0, "Código de la empresa", style);
        createCell(sheet, row, 1, "Código del producto", style);
        createCell(sheet, row, 2, "Código del billete", style);
        createCell(sheet, row, 3, "Código de la sucursal", style);
        createCell(sheet, row, 4, "Número", style);
        createCell(sheet, row, 5, "Serie de linea", style);
        createCell(sheet, row, 5, "Orden", style);

    }

    private void writeDataLines(SXSSFWorkbook workbook, SXSSFSheet sheet, List<GenerateComponentExcelResponse> colList){
        CellStyle style = workbook.createCellStyle();

        Font font = workbook.createFont();
        font.setFontHeightInPoints((short) 14);

        style.setFont(font);
        int rowNum = 2;
        for (GenerateComponentExcelResponse response : colList){
            Row row = sheet.createRow(rowNum);
            createCell(sheet, row, 0, response.getCompanyCode(), style);
            createCell(sheet, row, 1, response.getProductCode(), style);
            createCell(sheet, row, 2, response.getTicketCode(), style);
            createCell(sheet, row, 3, response.getBranchOfficeCode(), style);
            createCell(sheet, row, 4, response.getNumber(), style);
            createCell(sheet, row, 5, response.getLineSeries(), style);
            createCell(sheet, row, 6, response.getOrder(), style);
        }
    }

    public void export(HttpServletResponse response) throws IOException {
        try (SXSSFWorkbook workbook = new SXSSFWorkbook(15)) {
            workbook.setCompressTempFiles(true);

            for (List<GenerateComponentExcelResponse> cols : rows) {
                SXSSFSheet sheet = workbook.createSheet();
                writeHeaderLine(workbook, sheet);
                writeDataLines(workbook, sheet, cols);
            }
            try {

                workbook.write(outputStream);
                outputStream.flush();
                outputStream.close();
                workbook.dispose();
            } finally {
                workbook.dispose();
            }
            workbook.dispose();
        } catch (Exception ex) {
            log.info("Error writing excel:  ", ex);
            throw ex;
        }
    }


}

0

There are 0 answers