Hi all, this is my first post/topic here, and my English may not be so perfect.
This is the problem: I have 5 classes:
PianoDiStudi, which has a member of type
PianoDiStudiState (abstract),
NonApprovato,
Approvato and
NonEsaminato, of type PianoDiStudiState.
I must execute a query which retrieves only PianoDiStudi objects with a PianoDiStudiState of NonEsaminato concrete type.
I have tried with this code:
Code:
public List<T> getByExample(Object o){
Session sessione=null;
List<T> risultato=null;
try{
sessione=HibernateUtil.getSession();
risultato=(List<T>)sessione.createCriteria(this.model)
.add(Example.create(o)).list();
}
catch(HibernateException he){
he.printStackTrace();
sessione.close();
}
finally{
sessione.close();
}
return risultato;
}
This is part of a generic DAO class, model represents the type of the Object to retrieve. This doesn't work, the result list is empty. Any suggestions?
EDIT: tried also with:
Code:
risultato=(List<T>)sessione.createCriteria(this.model)
.add(Restrictions.eq("stato",pds.getStato())).list();
"stato" is the field of type PianoDiStudiState, and pds is a PianoDiStudiObject, with the stato set to NonEsaminato.
It retrieves all the objects, seems that it retrieves objects according to the static type (PianoDiStudiState), not the dynamic type (NonEsaminato), which is what I want.