Reputation: 659
I am trying to do a "many to many" jpa mapping.
I have a table called "Account":
@ManyToMany(fetch = FetchType.LAZY,
cascade = {
CascadeType.PERSIST,
CascadeType.MERGE
})
@JoinTable(name = "account_user",
joinColumns = { @JoinColumn(name = "account_id") },
inverseJoinColumns = { @JoinColumn(name = "user_id") })
private Set<User> users = new HashSet<>();
I have table called "User":
@ManyToMany(fetch = FetchType.LAZY,
cascade = {
CascadeType.PERSIST,
CascadeType.MERGE
},
mappedBy = "user")
@JsonIgnore
private Set<Account> accounts = new HashSet<>();
I get the following error:
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.bank.account.model.Account.user in com.bank.account.model.User.accounts
A join "many to many" table called "AccountUser" is supposed to be created by the mapping.
Any help or hint would be greatly appreciated it!!
Upvotes: 0
Views: 145
Reputation: 36103
MappedBy must refer to the attribute name in the target class. In your case it's users not user.
@ManyToMany(fetch = FetchType.LAZY,
cascade = {
CascadeType.PERSIST,
CascadeType.MERGE
},
mappedBy = "users")
@JsonIgnore
private Set<Account> accounts = new HashSet<>();
Upvotes: 1