Could not determine type for: java.util.List, at table: user, for columns: [org.hibernate.mapping.Column(login_record_list)]

在使用 Spring Data JPA 的时候,使用 @OneToMany @ManyToMany 报错如下

Caused by: org.hibernate.MappingException: Could not determine type for: java.util.List, at table: user, for columns: [org.hibernate.mapping.Column(login_record_list)]
 at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:455)
 at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:422)
 at org.hibernate.mapping.Property.isValid(Property.java:226)
 at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:597)
 at org.hibernate.mapping.RootClass.validate(RootClass.java:265)
 at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:329)
 at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:459)
 at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:892)
 ... 23 common frames omitted

 

解决方案: 

注解要么全部放在字段上,要么全部放在 get 方法上,不能混合使用!

因为我这个类其他的注解都是在标在字段上

所以,这种是正确的

  1. @ManyToMany(cascade = CascadeType.ALL)
  2.   @JoinTable(name = "user_authority",
  3.           joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")},
  4.           inverseJoinColumns = {@JoinColumn(name = "authority_id", referencedColumnName = "id")}
  5.   )
  6.   private List<Authority> authorities;

 

下面这种就会报错

  1. @OneToMany(mappedBy = "user")
  2.   public List<LoginRecord> getLoginRecordList() {
  3.       return loginRecordList;
  4.   }

只需要改成这样就能成功解决

  1. @OneToMany(mappedBy = "user")
  2. private List<LoginRecord> loginRecordList;

 

 

本文地址:https://liuyanzhao.com/7899.html

  • 微信
  • 赶快加我聊天吧
  • weinxin
  • 博客/Java交流群
  • 资源分享,问题解决,技术交流。群号:590480292
  • weinxin
言曌

发表评论

:?::razz::sad::evil::!::smile::oops::grin::eek::shock::???::cool::lol::mad::twisted::roll::wink::idea::arrow::neutral::cry::mrgreen:

目前评论:1   其中:访客  1   博主  0

    • avatar Marshal

      博主您好,我是一个Java小白,我也想写一个个人博客,希望您能给我一些建议