我希望为客户制作 jpa 实体,例如在 facebook 或 googe+ 上添加朋友有点困惑
This auto generates to code below,
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package entities;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
/**
*
* @author nikola
*/
@Entity
@Table(name = "Client")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Client.findAll", query = "SELECT c FROM Client c"),
@NamedQuery(name = "Client.findByClientId", query = "SELECT c FROM Client c WHERE c.clientId = :clientId"),
@NamedQuery(name = "Client.findByClientName", query = "SELECT c FROM Client c WHERE c.clientName = :clientName")})
public class Client implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "ClientId")
private Integer clientId;
@Size(max = 45)
@Column(name = "ClientName")
private String clientName;
@JoinTable(name = "Friends", joinColumns = {
@JoinColumn(name = "Client_ClientId", referencedColumnName = "ClientId")}, inverseJoinColumns = {
@JoinColumn(name = "Client_ClientId1", referencedColumnName = "ClientId")})
@ManyToMany
private List<Client> clientList;
@ManyToMany(mappedBy = "clientList")
private List<Client> clientList1;
public Client() {
}
public Client(Integer clientId) {
this.clientId = clientId;
}
public Integer getClientId() {
return clientId;
}
public void setClientId(Integer clientId) {
this.clientId = clientId;
}
public String getClientName() {
return clientName;
}
public void setClientName(String clientName) {
this.clientName = clientName;
}
@XmlTransient
public List<Client> getClientList() {
return clientList;
}
public void setClientList(List<Client> clientList) {
this.clientList = clientList;
}
@XmlTransient
public List<Client> getClientList1() {
return clientList1;
}
public void setClientList1(List<Client> clientList1) {
this.clientList1 = clientList1;
}
@Override
public int hashCode() {
int hash = 0;
hash += (clientId != null ? clientId.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 Client)) {
return false;
}
Client other = (Client) object;
if ((this.clientId == null && other.clientId != null) || (this.clientId != null && !this.clientId.equals(other.clientId))) {
return false;
}
return true;
}
@Override
public String toString() {
return "entities.Client[ clientId=" + clientId + " ]";
}
}
我有clientList 和clientList1,当我希望将客户添加到我的朋友列表时,不知道该使用哪一个。感谢您的任何建议。