Boas, galera,
Preciso fazer uma listagem, com algumas condições, mas não estou conseguindo navegar entre as propriedades das classes persistentes
ele diz que a propriedade não existe.
Segue o código:
@Override
public boolean isCadastrado(Lote objeto){
Criteria criteria = session.createCriteria(Lote.class);
criteria.add(Restrictions.like("numero", objeto.getNumero()));
criteria.add(Restrictions.eq("id", objeto.getId()));
criteria.add(Restrictions.eq("pastoLotes.pasto.retiro.propriedade.id", Sessao.getPropriedade().getId()));//Linha do erro
List<Reprodutor> lista = criteria.list();
if(lista.size()!=0){
//caso os ids sejam iguais quer dizer que o lote ja está cadastrado, porém se trata de uma alteração
if(objeto.getId()==lista.get(0).getId()){
return false;
}
}
return true;
}
package model;
import java.util.List;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Entity;
@Entity(name = "lote")
public class Lote {
private int id;
private List<PastoLote> pastoLotes;
private String numero;
private String obs;
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
public int getId() {
return id;
}
@OneToMany(mappedBy="lote")
public List<PastoLote> getPastoLotes() {
return pastoLotes;
}
public String getNumero() {
return numero;
}
public String getObs(){
return this.obs;
}
public void setId(int id) {
this.id = id;
}
public void setPastoLotes(List<PastoLote> pastoLotes) {
this.pastoLotes = pastoLotes;
}
public void setNumero(String numero) {
this.numero = numero;
}
public void setObs(String obs){
this.obs = obs;
}
}
package model;
import java.net.Proxy.Type;
import java.util.List;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
@Entity(name="pastolote")
public class PastoLote {
private int id;
private Lote lote;
private Pasto pasto;
private List<Animal> animais;
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
public int getId() {
return id;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="idLote")
public Lote getLote() {
return lote;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="idPasto")
public Pasto getPasto() {
return pasto;
}
@OneToMany(mappedBy="pastoLote")
public List<Animal> getAnimais(){
return this.animais;
}
public void setAnimais(List<Animal> animais){
this.animais = animais;
}
public void setId(int id) {
this.id = id;
}
public void setLote(Lote lote) {
this.lote = lote;
}
public void setPasto(Pasto pasto) {
this.pasto = pasto;
}
public PastoLote(int id)
{
this.id = id;
}
public PastoLote()
{
}
}
Obrigado