Я использую JPA 2.0 и использую сгенерированную схему.
Вот мое отображение:
@Entity
@Table(name = "CBV_USER")
public class CbvUser implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "Login")
private String login;
@Basic(optional = false)
@Column(name = "Password")
private String password;
@Basic(optional = false)
@Column(name = "Email")
private String email;
@Basic(optional = false)
@Column(name = "FirstName")
private String firstName;
@Basic(optional = false)
@Column(name = "LastName")
private String lastName;
@Basic(optional = false)
@Column(name = "Id")
private String id;
@Column(name = "Score")
private BigDecimal score;
@JoinTable(name = "FRIENDSHIP", joinColumns = {
@JoinColumn(name = "Login0", referencedColumnName = "Login")}, inverseJoinColumns = {
@JoinColumn(name = "Login1", referencedColumnName = "Login")})
@ManyToMany
private List<CbvUser> cbvUserList2;
@ManyToMany(mappedBy = "cbvUserList2")
private List<CbvUser> cbvUserList3;
public CbvUser() {
}
public CbvUser(String login) {
this.login = login;
}
public CbvUser(String login, String password, String email, String firstName, String lastName, String id) {
this.login = login;
this.password = password;
this.email = email;
this.firstName = firstName;
this.lastName = lastName;
this.id = id;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public BigDecimal getScore() {
return score;
}
public void setScore(BigDecimal score) {
this.score = score;
}
public List<CbvUser> getCbvUserList2() {
return cbvUserList2;
}
public void setCbvUserList2(List<CbvUser> cbvUserList2) {
this.cbvUserList2 = cbvUserList2;
}
public List<CbvUser> getCbvUserList3() {
return cbvUserList3;
}
public void setCbvUserList3(List<CbvUser> cbvUserList3) {
this.cbvUserList3 = cbvUserList3;
}
@Override
public int hashCode() {
int hash = 0;
hash += (login != null ? login.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof CbvUser)) {
return false;
}
CbvUser other = (CbvUser) object;
if ((this.login == null && other.login != null) || (this.login != null && !this.login.equals(other.login))) {
return false;
}
return true;
}
@Override
public String toString() {
return "models.CbvUser[login=" + login + "]";
}
}
Моя проблема в том, что я не могу понять, какдобавьте новую строку в таблицу соединений FRIENDSHIP через определенного CbvUser или через EntityManager.
Я буду очень признателен за любую помощь.