简体   繁体   English

类型 jakarta.persistence.EntityManagerFactory 不存在

[英]Type jakarta.persistence.EntityManagerFactory not present

I am learning Spring Data and creating a project.我正在学习 Spring 数据并创建一个项目。 Project like a list of exercises, save data in MySql thanks to Hibernate, but something wrong with it, and i don't know what Project like a list of exercises, save data in MySql thanks to Hibernate, 但它有问题,我不知道是什么

My controller:我的 controller:

@Controller
public class UserController {
    private final IUserService userService;

    @Autowired
    public UserController(IUserService userService) {
        this.userService = userService;
    }

    @PostMapping(path = "/user/create")
    public ResponseEntity<UserPojo> createUser(@RequestBody User user) {
        UserPojo result = userService.createUser(user);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @GetMapping(path = "/user/{id}")
    public ResponseEntity<UserPojo> getUser(@PathVariable Long id) {
        UserPojo result = userService.getUser(id);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }
}

Service:服务:

@Service
public class UserService implements IUserService {
    @PersistenceContext
    EntityManager entityManager;

    private final Converter converter;

    @Autowired
    public UserService(Converter converter) {
        this.converter = converter;
    }

    @Override
    @Transactional
    public UserPojo createUser(User user) {

        entityManager.persist(user);

        return converter.userToPojo(user);
    }

But when i ran it in Postman, i got this - I don't know why it appears:但是当我在 Postman 中运行它时,我得到了这个 - 我不知道它为什么会出现:

在此处输入图像描述

More info:更多信息:

java.lang.ClassNotFoundException: jakarta.persistence.EntityManagerFactory
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1449)
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1257)
    java.base/java.lang.Class.forName0(Native Method)
    java.base/java.lang.Class.forName(Class.java:488)
    java.base/java.lang.Class.forName(Class.java:467)
    java.base/sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114)

My POM and more code is here:我的 POM 和更多代码在这里:
GitHub GitHub

You have a weird and inconsistent mix of dependencies here您在这里有奇怪且不一致的依赖项组合

    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <version>4.1.9.Final</version>
    </dependency>

    <dependency>
      <groupId>org.hibernate.javax.persistence</groupId>
      <artifactId>hibernate-jpa-2.0-api</artifactId>
      <version>1.0.1.Final</version>
    </dependency>

    <dependency>
      <groupId>org.springframework.data</groupId>
      <artifactId>spring-data-jpa</artifactId>
      <version>3.0.0</version>
    </dependency>

When you use Spring Data JPA version 3.0.0 you should use Hibernate 6+.当您使用 Spring 数据 JPA 版本 3.0.0 时,您应该使用 Hibernate 6+。 To get started you shouldn't specify the versions for Hibernate since those are specified in the Spring Data JPA pom.xml .要开始,您不应指定 Hibernate 的版本,因为这些版本在 Spring 数据 JPA pom.xml中指定。

And you shouldn't need hibernate-jpa-2.0-api at all.而且您根本不需要hibernate-jpa-2.0-api

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 一个组件需要一个无法找到的类型为“javax.persistence.EntityManagerFactory”的 bean - A component required a bean of type 'javax.persistence.EntityManagerFactory' that could not be found Spring JPA(Hibernate)没有类型的限定bean:javax.persistence.EntityManagerFactory - Spring JPA (Hibernate) No qualifying bean of type: javax.persistence.EntityManagerFactory 使用Spring 4未定义类型为[javax.persistence.EntityManagerFactory]的合格Bean - No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined Using Spring 4 NoSuchBeanDefinitionException:没有可用的“javax.persistence.EntityManagerFactory”类型的合格 bean - NoSuchBeanDefinitionException: No qualifying bean of type 'javax.persistence.EntityManagerFactory' available 没有定义类型为[javax.persistence.EntityManagerFactory]的合格bean - No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined 考虑在配置中定义类型为&#39;javax.persistence.EntityManagerFactory&#39;的bean - Consider defining a bean of type 'javax.persistence.EntityManagerFactory' in your configuration 没有可用于OSGi应用程序的&#39;javax.persistence.EntityManagerFactory&#39;类型的合格Bean - No qualifying bean of type 'javax.persistence.EntityManagerFactory' available for OSGi Application 没有定义类型为[javax.persistence.EntityManagerFactory]的合格Bean。“}} - No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined"}} com.example.daoImpl.FileDaoImpl中的field entityManagerFactory需要找不到类型为&#39;javax.persistence.EntityManagerFactory&#39;的bean - Field entityManagerFactory in com.example.daoImpl.FileDaoImpl required a bean of type 'javax.persistence.EntityManagerFactory' that could not be found 无法配置EntityManagerFactory(无持久性) - Unable to configure EntityManagerFactory (No Persistence)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM