Home > database >  The type jakarta.persistence.EntityManagerFactory cannot be resolved. It is indirectly referenced fr
The type jakarta.persistence.EntityManagerFactory cannot be resolved. It is indirectly referenced fr

Time:10-13

package sth.hibernate;

import org.hibernate.cfg.Configuration;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import sth.hibernate.entitty.Users;

public class App {
    public static void main(String[] args) {
        
        SessionFactory factory = new Configuration()
                                .configure("hibernate.cfg.xml")
                                .addAnnotatedClass(Users.class)
                                .buildSessionFactory();
        Session session = factory.getCurrentSession();
        
        try {
            
        } finally {
            factory.close();
            session.close();
        }

    }
}

When I try to getCurrentSession it's show me this error:

"The type jakarta.persistence.EntityManagerFactory cannot be resolved. It is indirectly referenced from required .class files"

CodePudding user response:

Looks like you miss the jakarta.persistence-api dependency in your class path.

If you are using maven, add the following to your pom.xml

<dependency>
    <groupId>jakarta.persistence</groupId>
    <artifactId>jakarta.persistence-api</artifactId>
    <version>3.1.0</version>
</dependency>
  • Related