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;

 

posted @ 2016-06-17 17:41  code.world  Views(4358)  Comments(0Edit  收藏  举报