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;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM