Hi people, considering I have the following code:
Entities:
Code:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public class Pessoa {
@Id
@SequenceGenerator(name="pessoa_seq", sequenceName="PESSOA_SEQ", allocationSize=1)
@GeneratedValue(strategy=GenerationType.AUTO, generator="pessoa_seq")
private Long id;
@OneToMany(mappedBy="pessoa", fetch=FetchType.EAGER, cascade=CascadeType.ALL) // At this time, I want Eager fetching
private Set<Telefone> telefones;
// Other properties are omitted
public Pessoa(){
}
// Getters and setters
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Pessoa other = (Pessoa) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
Code:
@Entity
public class Cliente extends Pessoa {
@Temporal(TemporalType.DATE)
private Date clienteDesde;
// Getters and Setters omitted
}
And my DAO, supposing I'm passing a Cliente as the Generic Type:
Code:
@SuppressWarnings("unchecked")
@Override
@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
public List<T> findByExample(T entity) {
Example example = Example.create(entity).ignoreCase().enableLike(MatchMode.ANYWHERE).setPropertySelector(new PropertySelector(){
@Override
public boolean include(Object arg0, String arg1, Type arg2){
Sytem.out.println(arg0 + " - " + arg1 + " - " + arg2);
}
});
return getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(entity.getClass()).add(example).list();
}
Why does my include method never prints the inner OneToMany properties from Pessoa (like Set<Telefone> telefones), only the other attributes?
Thanks in advance.