[英]SpringBoot JPA MappedBy reference an unknown target entity property
The error: hibernate.AnnotationException: mappedBy reference an unknown target entity property 错误:hibernate.AnnotationException:mappedBy引用未知的目标实体属性
I know why the error is here but the longer i stare at it the more I cannot find it :). 我知道为什么会出现错误,但是我盯着它看的时间越长,我就越找不到它:)。 I just need another persons perspective.
我只需要另一个人的角度。
Here are the MySQL tables: 这是MySQL表:
Then I have entities for User, Company and Transaction. 然后,我有用户,公司和交易的实体。
The relationships are shown here: 关系如下所示:
Transaction: 交易:
@ManyToOne
@JoinColumn(name = "userId")
User user;
@ManyToOne
@JoinColumn(name = "companyId")
Company company;
Company 公司
@JsonIgnore
@OneToMany(mappedBy = "transaction")
List<Transaction> transactions;
User 用户
@JsonIgnore
@OneToMany(mappedBy = "transaction")
List<Transaction> transactions;
Here is the full error: 这是完整的错误:
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: top100.models.Transaction.transaction in top100.models.User.transactions
So the error is to do with the relationship but I cannot spot my mistake. 因此,错误与关系有关,但我无法发现我的错误。
Thanks :) 谢谢 :)
Maybe you try mapped by field "user". 也许您尝试按“用户”字段进行映射。 Probably you may see asked this question in there Understanding mappedBy annotation in Hibernate
可能您会在“ 了解Hibernate中的mappingBy批注”中看到这个问题。
Company 公司
@JsonIgnore
@OneToMany(mappedBy = "company")
List<Transaction> transactions;
User 用户
@JsonIgnore
@OneToMany(mappedBy = "user")
List<Transaction> transactions;
The mappedBy is referring to the name of the field that is connected to. mappingBy指的是连接到的字段的名称。 The link that @Aleksandr Zorin provided has more details.
@Aleksandr Zorin提供的链接具有更多详细信息。 I recommand you to take a look :)
我建议你看看:)
It should be 它应该是
Company 公司
@JsonIgnore
@OneToMany(mappedBy = "company")
List<Transaction> transactions;
and 和
User 用户
@JsonIgnore
@OneToMany(mappedBy = "user")
List<Transaction> transactions;
In mappedBy property you are specifying field in referenced table by which it should be mapped. 在mapledBy属性中,您在引用表中指定字段,应以此字段进行映射。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.