我有ManyToMany
这样的映射:
@XmlTransient
@ManyToMany(cascade = {CascadeType.ALL})
@JoinTable(name = "users_clients",
joinColumns = {@JoinColumn(name = "user_id")},
inverseJoinColumns = @JoinColumn(name = "client_id"))
public List<Client> getClients() {
return clients;
}
另一方:
@ManyToMany(mappedBy = "clients")
private List<User> users = new ArrayList<User>();
因为你可以看到我有JoinColumn name = user_id
和client_id
但是hibernate mapps这个列的名称为userS_id和clientS_id作为它们的表名。为什么会这样?有什么建议吗?
答案 0 :(得分:0)
尝试在@JoinColumn
注释中指定列名称。你还错过了inverseJoinColumns
@JoinTable(name = "users_clients",
joinColumns = {
@JoinColumn(name = "user_id", referencedColumnName="user_id")},
inverseJoinColumns = {
@JoinColumn(name = "client_id", referencedColumnName="client_id")})