Vy Do
Vy Do

Reputation: 52508

Upgrade from Spring Boot 2.7.2 to Spring Boot 3.0.0-SNAPSHOT: java: package javax.persistence does not exist

When I use Spring Boot 2.7.2 everything works ok. After upgrade to version 3.0.0-SNAPSHOT, I have

My pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.0-SNAPSHOT</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>spring_jwt</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <name>spring-boot-security-jwt</name>
    <description>spring_jwt</description>
    <properties>
        <java.version>18</java.version>
    </properties>
    <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-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-api</artifactId>
            <version>0.11.5</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-impl</artifactId>
            <version>0.11.5</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-jackson</artifactId>
            <version>0.11.5</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api</artifactId>
            <version>4.0.0</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.1</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-hibernate5</artifactId>
            <version>2.13.3</version>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.6.9</version>
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-security</artifactId>
            <version>1.6.9</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.11.0</version>
        </dependency>

        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>6.20.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports-fonts</artifactId>
            <version>6.20.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports-functions</artifactId>
            <version>6.20.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports-metadata</artifactId>
            <version>6.20.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports-chart-themes</artifactId>
            <version>6.20.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports-annotation-processors</artifactId>
            <version>6.20.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports-castor</artifactId>
            <version>6.20.0</version>
        </dependency>


<!--        <dependency>-->
<!--            <groupId>net.sf.jasperreports</groupId>-->
<!--            <artifactId>liberation-fonts</artifactId>-->
<!--            <version>1.0</version>-->
<!--        </dependency>-->
        <!-- https://mvnrepository.com/artifact/com.mpobjects.jasperreports.font/jasperreports-fonts-liberation -->
        <dependency>
            <groupId>com.mpobjects.jasperreports.font</groupId>
            <artifactId>jasperreports-fonts-liberation</artifactId>
            <version>2.1.2</version>
        </dependency>


        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports-chart-customizers</artifactId>
            <version>6.20.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports-custom-visualization</artifactId>
            <version>6.20.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.4</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

<!--        <dependency>-->
<!--            <groupId>com.stimulsoft</groupId>-->
<!--            <artifactId>stimulsoft-reports-report</artifactId>-->
<!--            <version>2022.3.3</version>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>com.stimulsoft</groupId>-->
<!--            <artifactId>stimulsoft-reports-web</artifactId>-->
<!--            <version>2022.3.3</version>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>com.stimulsoft</groupId>-->
<!--            <artifactId>stimulsoft-reports-base</artifactId>-->
<!--            <version>2022.3.3</version>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>com.stimulsoft</groupId>-->
<!--            <artifactId>stimulsoft-reports-viewer</artifactId>-->
<!--            <version>2022.3.3</version>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>com.stimulsoft</groupId>-->
<!--            <artifactId>stimulsoft-reports-samples</artifactId>-->
<!--            <version>2022.3.3</version>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>com.stimulsoft</groupId>-->
<!--            <artifactId>stimulsoft-reports-webviewer</artifactId>-->
<!--            <version>2022.3.3</version>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>com.stimulsoft</groupId>-->
<!--            <artifactId>stimulsoft-reports-lib</artifactId>-->
<!--            <version>2022.3.3</version>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>com.stimulsoft</groupId>-->
<!--            <artifactId>stimulsoft-reports-webdesigner</artifactId>-->
<!--            <version>2022.3.3</version>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>com.stimulsoft</groupId>-->
<!--            <artifactId>reports</artifactId>-->
<!--            <version>2022.3.3</version>-->
<!--            <type>pom</type>-->
<!--        </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>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>maven-central</id>
            <name>Maven Central</name>
            <url>https://repo1.maven.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>

        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>

        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>

        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <releases>
                <enabled>false</enabled>
            </releases>
        </pluginRepository>
    </pluginRepositories>
</project>

Entity

package com.example.BLModel;

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MapsId;
import javax.persistence.Table;
import java.time.OffsetDateTime;

@Entity
@Table(name = "account")
public class Account {
    @EmbeddedId
    private AccountId id;

    @MapsId("tenantId")
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "tenant_id", nullable = false)
    private Tenant tenant;

    @Column(name = "account_number", nullable = false, length = 32)
    private String accountNumber;

    @Column(name = "account_name", nullable = false, length = 128)
    private String accountName;

    @Column(name = "account_name_english", length = 128)
    private String accountNameEnglish;

    @Column(name = "account_name_chinese", length = 128)
    private String accountNameChinese;

    @Column(name = "account_name_korean", length = 128)
    private String accountNameKorean;

    @Column(name = "description", length = 512)
    private String description;

    @Column(name = "parent_id")
    private Short parentId;

    @Column(name = "internal_code_id", length = 128)
    private String internalCodeId;

    @Column(name = "grade")
    private Short grade;

    @Column(name = "is_parent", nullable = false)
    private Boolean isParent = false;

    @Column(name = "account_category_kind", nullable = false)
    private Short accountCategoryKind;

    @Column(name = "is_postable_in_foreign_currency", nullable = false)
    private Boolean isPostableInForeignCurrency = false;

    @Column(name = "detail_by_account_object", nullable = false)
    private Boolean detailByAccountObject = false;

    @Column(name = "account_object_type")
    private Short accountObjectType;

    @Column(name = "detail_by_bank_account", nullable = false)
    private Boolean detailByBankAccount = false;

    @Column(name = "detail_by_job", nullable = false)
    private Boolean detailByJob = false;

    @Column(name = "detail_by_job_kind")
    private Short detailByJobKind;

    @Column(name = "detail_by_project_work", nullable = false)
    private Boolean detailByProjectWork = false;

    @Column(name = "detail_by_project_work_kind")
    private Short detailByProjectWorkKind;

    @Column(name = "detail_by_order", nullable = false)
    private Boolean detailByOrder = false;

    @Column(name = "detail_by_order_kind")
    private Short detailByOrderKind;

    @Column(name = "detail_by_contract", nullable = false)
    private Boolean detailByContract = false;

    @Column(name = "detail_by_contract_kind")
    private Short detailByContractKind;

    @Column(name = "detail_by_expense_item", nullable = false)
    private Boolean detailByExpenseItem = false;

    @Column(name = "detail_by_expense_item_kind")
    private Short detailByExpenseItemKind;

    @Column(name = "detail_by_department", nullable = false)
    private Boolean detailByDepartment = false;

    @Column(name = "detail_by_department_kind")
    private Short detailByDepartmentKind;

    @Column(name = "detail_by_list_item", nullable = false)
    private Boolean detailByListItem = false;

    @Column(name = "detail_by_list_item_kind")
    private Short detailByListItemKind;

    @Column(name = "active_status", nullable = false)
    private Boolean activeStatus = false;

    @Column(name = "created")
    private OffsetDateTime created;

    @Column(name = "created_by", length = 64)
    private String createdBy;

    @Column(name = "modified")
    private OffsetDateTime modified;

    @Column(name = "modified_by", length = 64)
    private String modifiedBy;

    @Column(name = "sort_internal_code_id", length = 128)
    private String sortInternalCodeId;

    @Column(name = "detail_by_pu_contract", nullable = false)
    private Boolean detailByPuContract = false;

    @Column(name = "detail_by_pu_contract_kind")
    private Short detailByPuContractKind;

    public AccountId getId() {
        return id;
    }

    public void setId(AccountId id) {
        this.id = id;
    }

    public Tenant getTenant() {
        return tenant;
    }

    public void setTenant(Tenant tenant) {
        this.tenant = tenant;
    }

    public String getAccountNumber() {
        return accountNumber;
    }

    public void setAccountNumber(String accountNumber) {
        this.accountNumber = accountNumber;
    }

    public String getAccountName() {
        return accountName;
    }

    public void setAccountName(String accountName) {
        this.accountName = accountName;
    }

    public String getAccountNameEnglish() {
        return accountNameEnglish;
    }

    public void setAccountNameEnglish(String accountNameEnglish) {
        this.accountNameEnglish = accountNameEnglish;
    }

    public String getAccountNameChinese() {
        return accountNameChinese;
    }

    public void setAccountNameChinese(String accountNameChinese) {
        this.accountNameChinese = accountNameChinese;
    }

    public String getAccountNameKorean() {
        return accountNameKorean;
    }

    public void setAccountNameKorean(String accountNameKorean) {
        this.accountNameKorean = accountNameKorean;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Short getParentId() {
        return parentId;
    }

    public void setParentId(Short parentId) {
        this.parentId = parentId;
    }

    public String getInternalCodeId() {
        return internalCodeId;
    }

    public void setInternalCodeId(String internalCodeId) {
        this.internalCodeId = internalCodeId;
    }

    public Short getGrade() {
        return grade;
    }

    public void setGrade(Short grade) {
        this.grade = grade;
    }

    public Boolean getIsParent() {
        return isParent;
    }

    public void setIsParent(Boolean isParent) {
        this.isParent = isParent;
    }

    public Short getAccountCategoryKind() {
        return accountCategoryKind;
    }

    public void setAccountCategoryKind(Short accountCategoryKind) {
        this.accountCategoryKind = accountCategoryKind;
    }

    public Boolean getIsPostableInForeignCurrency() {
        return isPostableInForeignCurrency;
    }

    public void setIsPostableInForeignCurrency(Boolean isPostableInForeignCurrency) {
        this.isPostableInForeignCurrency = isPostableInForeignCurrency;
    }

    public Boolean getDetailByAccountObject() {
        return detailByAccountObject;
    }

    public void setDetailByAccountObject(Boolean detailByAccountObject) {
        this.detailByAccountObject = detailByAccountObject;
    }

    public Short getAccountObjectType() {
        return accountObjectType;
    }

    public void setAccountObjectType(Short accountObjectType) {
        this.accountObjectType = accountObjectType;
    }

    public Boolean getDetailByBankAccount() {
        return detailByBankAccount;
    }

    public void setDetailByBankAccount(Boolean detailByBankAccount) {
        this.detailByBankAccount = detailByBankAccount;
    }

    public Boolean getDetailByJob() {
        return detailByJob;
    }

    public void setDetailByJob(Boolean detailByJob) {
        this.detailByJob = detailByJob;
    }

    public Short getDetailByJobKind() {
        return detailByJobKind;
    }

    public void setDetailByJobKind(Short detailByJobKind) {
        this.detailByJobKind = detailByJobKind;
    }

    public Boolean getDetailByProjectWork() {
        return detailByProjectWork;
    }

    public void setDetailByProjectWork(Boolean detailByProjectWork) {
        this.detailByProjectWork = detailByProjectWork;
    }

    public Short getDetailByProjectWorkKind() {
        return detailByProjectWorkKind;
    }

    public void setDetailByProjectWorkKind(Short detailByProjectWorkKind) {
        this.detailByProjectWorkKind = detailByProjectWorkKind;
    }

    public Boolean getDetailByOrder() {
        return detailByOrder;
    }

    public void setDetailByOrder(Boolean detailByOrder) {
        this.detailByOrder = detailByOrder;
    }

    public Short getDetailByOrderKind() {
        return detailByOrderKind;
    }

    public void setDetailByOrderKind(Short detailByOrderKind) {
        this.detailByOrderKind = detailByOrderKind;
    }

    public Boolean getDetailByContract() {
        return detailByContract;
    }

    public void setDetailByContract(Boolean detailByContract) {
        this.detailByContract = detailByContract;
    }

    public Short getDetailByContractKind() {
        return detailByContractKind;
    }

    public void setDetailByContractKind(Short detailByContractKind) {
        this.detailByContractKind = detailByContractKind;
    }

    public Boolean getDetailByExpenseItem() {
        return detailByExpenseItem;
    }

    public void setDetailByExpenseItem(Boolean detailByExpenseItem) {
        this.detailByExpenseItem = detailByExpenseItem;
    }

    public Short getDetailByExpenseItemKind() {
        return detailByExpenseItemKind;
    }

    public void setDetailByExpenseItemKind(Short detailByExpenseItemKind) {
        this.detailByExpenseItemKind = detailByExpenseItemKind;
    }

    public Boolean getDetailByDepartment() {
        return detailByDepartment;
    }

    public void setDetailByDepartment(Boolean detailByDepartment) {
        this.detailByDepartment = detailByDepartment;
    }

    public Short getDetailByDepartmentKind() {
        return detailByDepartmentKind;
    }

    public void setDetailByDepartmentKind(Short detailByDepartmentKind) {
        this.detailByDepartmentKind = detailByDepartmentKind;
    }

    public Boolean getDetailByListItem() {
        return detailByListItem;
    }

    public void setDetailByListItem(Boolean detailByListItem) {
        this.detailByListItem = detailByListItem;
    }

    public Short getDetailByListItemKind() {
        return detailByListItemKind;
    }

    public void setDetailByListItemKind(Short detailByListItemKind) {
        this.detailByListItemKind = detailByListItemKind;
    }

    public Boolean getActiveStatus() {
        return activeStatus;
    }

    public void setActiveStatus(Boolean activeStatus) {
        this.activeStatus = activeStatus;
    }

    public OffsetDateTime getCreated() {
        return created;
    }

    public void setCreated(OffsetDateTime created) {
        this.created = created;
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public OffsetDateTime getModified() {
        return modified;
    }

    public void setModified(OffsetDateTime modified) {
        this.modified = modified;
    }

    public String getModifiedBy() {
        return modifiedBy;
    }

    public void setModifiedBy(String modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    public String getSortInternalCodeId() {
        return sortInternalCodeId;
    }

    public void setSortInternalCodeId(String sortInternalCodeId) {
        this.sortInternalCodeId = sortInternalCodeId;
    }

    public Boolean getDetailByPuContract() {
        return detailByPuContract;
    }

    public void setDetailByPuContract(Boolean detailByPuContract) {
        this.detailByPuContract = detailByPuContract;
    }

    public Short getDetailByPuContractKind() {
        return detailByPuContractKind;
    }

    public void setDetailByPuContractKind(Short detailByPuContractKind) {
        this.detailByPuContractKind = detailByPuContractKind;
    }

}

error

java: package javax.persistence does not exist

enter image description here How to fix?

Upvotes: 18

Views: 40916

Answers (5)

Pavel
Pavel

Reputation: 328

In my case this was caused by old version of hibernate-jcache. Fixed by updating to the newest one:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-jcache</artifactId>
    <version>6.2.2.Final</version>
</dependency>

Upvotes: 0

yuyu5
yuyu5

Reputation: 476

I just went through this hell myself for at least 6 hours. The real answer is described in the Spring Boot migration guide's section where they point us to base Spring's replacement of javax with jakarta.

Basically all you have to do is a Ctrl+Shift+F replacement of (almost) anywhere you previously had javax and swap it with jakarta. If you're like me, for some reason my IDE didn't autocomplete or recognize it until I manually typed it in, so don't let your IDE fool you if it does the same thing. FWIW, this conclusion has been supported by others as well, but it's just super unclear from the author's docs that this simple of a change is all we needed to do.

I hope this helps you to not waste half your day like it did me xD

Upvotes: 13

Jack Aguilar
Jack Aguilar

Reputation: 1

Just delete the jakarta dependency. Since it has its full content in the ultimate version of Intellij Idea. In your case, this one:

<dependency>
        <groupId>jakarta.xml.bind</groupId>
        <artifactId>jakarta.xml.bind-api</artifactId>
        <version>4.0.0</version>
    </dependency>

And add these dependencies:

<dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>javax.persistence-api</artifactId>
        <version>2.2</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>javax.transaction-api</artifactId>
        <version>1.2</version>
    </dependency>

Upvotes: 0

ropa8
ropa8

Reputation: 479

There is no need to add hibernate-entitymanager artifact as dependency in pom.xml.

spring-boot-starter-data-jpa artifact is enough. You shoud just consider the following points.

Replace Java EE 8 With Jakarta EE 9 APIs:

Spring Boot 3.0 will be the first version of Spring Boot that makes use of Jakarta EE 9 APIs (jakarta.) instead of EE 8 (javax.). This entails that we will have to look for EE 8 imports with javax.* and replace them with jakarta.*. Typical EE 8 packages used in Spring Boot microservices include the following:

  • javax.persistence.*

  • javax.validation.*

  • javax.servlet.*

  • javax.annotation.*

  • javax.transaction.*

  • etc.

Be aware that packages such as javax.sql.* and javax.crypto.* come from Java 17 JDK, not from EE 8, so they are safe to stay.

References:

Notes on Spring-Boot-3 Upgrade

Preparing for Spring-Boot-3-0

Upvotes: 35

Vy Do
Vy Do

Reputation: 52508

Change "JPA API from Java EE" --> "JPA API from Jakarta EE", and add

<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>6.0.0.Alpha7</version>
    <type>pom</type>
</dependency>

Upvotes: 0

Related Questions