Ola pessoal sou novo aqui estou coomeçando agora e estou com uma duvida e gostaria que vcs me ajudassem.
Fiz um sistema de castro simples so pra ter noção e poder estudar os codigos melhores.
Um sistema de cadastro de animais e setor esse sistema e um tutorial do netbeans.
tenho 2 classes Animal e Pavilion
[code]package classes;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
/**
*
-
@author operador
*/
@Entity
public class Animal implements Serializable {private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;@Column(name=“animalName”)
private String name;
private String kind;
private String weight;@ManyToOne
private Pavilion pavilion;public String getKind() {
return kind;
}public void setKind(String kind) {
this.kind = kind;
}public String getName() {
return name;
}public void setName(String name) {
this.name = name;
}public Pavilion getPavilion() {
return pavilion;
}public void setPavilion(Pavilion pavilion) {
this.pavilion = pavilion;
}public String getWeight() {
return weight;
}public void setWeight(String weight) {
this.weight = weight;
}public Long getId() {
return id;
}public void setId(Long id) {
this.id = id;
}@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.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 Animal)) {
return false;
}
Animal other = (Animal) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}@Override
public String toString() {
return “classes.Animal[id=” + id + “]”;
}
}
[/code]
[code]package classes;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
/**
*
-
@author operador
*/
@Entity
public class Pavilion implements Serializable {private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)private Long id;
@Column(name=“pavilionName”)
private String name;private String address;
@OneToMany(mappedBy=“pavilion”)
private Collection animals;public String getAddress() {
return address;
}public void setAddress(String address) {
this.address = address;
}public Collection getAnimals() {
return animals;
}public void setAnimals(Collection animals) {
this.animals = animals;
}public String getName() {
return name;
}public void setName(String name) {
this.name = name;
}public Long getId() {
return id;
}public void setId(Long id) {
this.id = id;
}@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.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 Pavilion)) {
return false;
}
Pavilion other = (Pavilion) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}@Override
public String toString() {
return “classes.Pavilion[id=” + id + “]”;
}
}
[/code]
o que acontece e que quando vou cadastrar o animal e tenho que selecionar o Pavilion so aparece o sequinte:
so esta buscando pelo id eu gostaria que buscasse pelo nome se puderem me ajudar vlw