Stworzyłem sobie w bazie dwie tabele Przedmioty(ID, Nazwa) i Wykladowcy(ID, Imie, Nazwisko). Połączyłem je relacją wiele do wielu, co utworzyło mi kolejną tabelkę. Chciałbym wypisać teraz w tabeli okna programu, Nazwisko oraz przypisany do niego Przedmiot. Pracuje w netbeansie, więc zmapowałem sobie tabelki z bazy, co utworzyło mi automatycznie dwie klasy. Oto jedna z nich:
@Entity
@Table(name = "przedmioty")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Przedmioty.findAll", query = "SELECT p FROM Przedmioty p"),
@NamedQuery(name = "Przedmioty.findByIdprzedmioty", query = "SELECT p FROM Przedmioty p WHERE p.idprzedmioty = :idprzedmioty"),
@NamedQuery(name = "Przedmioty.findByPrzedmiot", query = "SELECT p FROM Przedmioty p WHERE p.przedmiot = :przedmiot")})
public class Przedmioty implements Serializable {
@Transient
private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "idprzedmioty")
private Integer idprzedmioty;
@Basic(optional = false)
@Column(name = "Przedmiot")
private String przedmiot;
@JoinTable(name = "wykladowcy_has_przedmioty", joinColumns = {
@JoinColumn(name = "przedmioty_idprzedmioty", referencedColumnName = "idprzedmioty")}, inverseJoinColumns = {
@JoinColumn(name = "wykladowcy_idwykladowcy", referencedColumnName = "idwykladowcy")})
@ManyToMany
private Collection<Wykladowcy> wykladowcyCollection;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "przedmiotyIdprzedmioty")
private Collection<Ankiety> ankietyCollection;
public Przedmioty() {
}
public Przedmioty(Integer idprzedmioty) {
this.idprzedmioty = idprzedmioty;
}
public Przedmioty(Integer idprzedmioty, String przedmiot) {
this.idprzedmioty = idprzedmioty;
this.przedmiot = przedmiot;
}
public Integer getIdprzedmioty() {
return idprzedmioty;
}
public void setIdprzedmioty(Integer idprzedmioty) {
Integer oldIdprzedmioty = this.idprzedmioty;
this.idprzedmioty = idprzedmioty;
changeSupport.firePropertyChange("idprzedmioty", oldIdprzedmioty, idprzedmioty);
}
public String getPrzedmiot() {
return przedmiot;
}
public void setPrzedmiot(String przedmiot) {
String oldPrzedmiot = this.przedmiot;
this.przedmiot = przedmiot;
changeSupport.firePropertyChange("przedmiot", oldPrzedmiot, przedmiot);
}
@XmlTransient
public Collection<Wykladowcy> getWykladowcyCollection() {
return wykladowcyCollection;
}
public void setWykladowcyCollection(Collection<Wykladowcy> wykladowcyCollection) {
this.wykladowcyCollection = wykladowcyCollection;
}
@XmlTransient
public Collection<Ankiety> getAnkietyCollection() {
return ankietyCollection;
}
public void setAnkietyCollection(Collection<Ankiety> ankietyCollection) {
this.ankietyCollection = ankietyCollection;
}
@Override
public int hashCode() {
int hash = 0;
hash += (idprzedmioty != null ? idprzedmioty.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 Przedmioty)) {
return false;
}
Przedmioty other = (Przedmioty) object;
if ((this.idprzedmioty == null && other.idprzedmioty != null) || (this.idprzedmioty != null && !this.idprzedmioty.equals(other.idprzedmioty))) {
return false;
}
return true;
}