错误: hibernate.AnnotationException: mappedBy引用了未知的目标实体属性
我知道为什么会出现这个错误,但我盯着它看的时间越长,我就越找不到它:)。我只是需要另一个人的观点。
以下是MySQL表:
然后我有User、Company和Transaction实体。
关系如下所示:
事务:
@ManyToOne
@JoinColumn(name = "userId")
User user;
@ManyToOne
@JoinColumn(name = "companyId")
Company company;
公司
@JsonIgnore
@OneToMany(mappedBy = "transaction")
List<Transaction> transactions;
用户
@JsonIgnore
@OneToMany(mappedBy = "transaction")
List<Transaction> transactions;
下面是完整的错误:
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
所以错误与关系有关,但我找不到我的错误。
谢谢:)
发布于 2018-07-21 03:12:55
公司
@JsonIgnore
@OneToMany(mappedBy = "company")
List<Transaction> transactions;
用户
@JsonIgnore
@OneToMany(mappedBy = "user")
List<Transaction> transactions;
mappedBy指的是连接到的字段的名称。@Aleksandr Zorin提供的链接有更多细节。我建议您看一下:)
发布于 2018-07-21 01:18:04
也许你可以尝试通过字段"user“来映射。您可能会在Understanding mappedBy annotation in Hibernate中看到被问到这个问题
发布于 2018-07-21 14:39:41
它应该是
公司
@JsonIgnore
@OneToMany(mappedBy = "company")
List<Transaction> transactions;
和
用户
@JsonIgnore
@OneToMany(mappedBy = "user")
List<Transaction> transactions;
在mappedBy属性中,您正在指定引用表中的字段,它将通过该字段进行映射。
https://stackoverflow.com/questions/51447389
复制相似问题