zoukankan      html  css  js  c++  java
  • hibernate之persistence错误

    错误码:

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory

    上述错误码nested exception is javax.persistence.PersistenceException可知是实体类实例化的时候报错,所以应该查看实体类是否有注解、字段书写的错误,我的是因为之前做关联,后面去掉了,但注解没有去掉导致,出错代码:

        @NotNull
        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumn(name = "user_id", nullable = false)
        private long userId;
    
    之前是:
    
        @NotNull
        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumn(name = "user_id", nullable = false)
        private User user;

    正确的是:
      @JoinColumn(name = "user_id", nullable = false)
      private long userId;
  • 相关阅读:
    AutoMapper使用
    C#网络编程
    ASP.NET MVC (Razor)开发
    React的React Native
    WCF搭建
    异步编程
    Async和Await进行异步编程
    C#开发中使用配置文件
    NET转Java
    net 开源组件
  • 原文地址:https://www.cnblogs.com/sunjf/p/hibernate_persistence.html
Copyright © 2011-2022 走看看