錯誤碼:
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;