【问题标题】:Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property:调用 init 方法失败;嵌套异常是 org.hibernate.AnnotationException: mappedBy reference an unknown target entity property:
【发布时间】:2018-12-10 17:25:54
【问题描述】:

在我的 Subject 表和 Group 表之间创建关系 ManyToMany。但我对“mappedBy

有疑问

学科类别:

@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@Fetch(value = FetchMode.SUBSELECT)
@JoinTable(
    name = "ugroup_subject",
    joinColumns = @JoinColumn(
        name = "subject_id", referencedColumnName = "id"),
    inverseJoinColumns = @JoinColumn(
        name = "group_id", referencedColumnName = "id")

)
    List<Group> groups;

组类:

 @ManyToMany(mappedBy = "group")
    private List<Subject> subjects;

这是我的错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.example.tim.model.Subject.group in com.example.tim.model.Group.subjects

我在哪里做错了? 提前感谢您的帮助!

【问题讨论】:

  • 您的资源被命名为groups 而不是group

标签: java spring hibernate spring-boot


【解决方案1】:

这里有错别字

@ManyToMany(mappedBy = "group") 更改为@ManyToMany(mappedBy = "groups")

【讨论】:

  • 我遇到了类似的问题。使用 @ManyToMany(mappedBy = "Groups") 时出错。更改为 @ManyToMany(mappedBy = "groups") 时已修复
猜你喜欢
  • 2013-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-09
  • 2011-11-24
  • 1970-01-01
  • 1970-01-01
  • 2017-06-19
相关资源
最近更新 更多