Hello, I have to get this Criteria to get houses that have avatar, avatar is Photo type:
Code:
public class House {
@OneToOne
private Photo avatar;
}
Code:
public class Photo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id_photo")
private Long idPhoto;
private String name;
private String url;
// other codes here
}
This is the Criteria:
Code:
Criteria crit = session.createCriteria(House.class);
crit.add(Restrictions.isNotNull("avatar"));
Criteria tipoCrit = crit.createCriteria("modality");
tipoCrit.add(Restrictions.eq("typeModality", "Sale"));
crit.addOrder(Order.desc("dateInclusion"));
List results = crit.list();
return results;
To get avatar photo of the house i test with this in JSP:
Code:
<c:when test="${house.avatar.idPhoto eq null}">
And this is stacktrace:
Code:
root cause
java.lang.NumberFormatException: For input string: "avatar"
java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
java.lang.Integer.parseInt(Integer.java:449)
java.lang.Integer.parseInt(Integer.java:499)
javax.el.ListELResolver.coerce(ListELResolver.java:167)
javax.el.ListELResolver.getValue(ListELResolver.java:51)
javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
org.apache.el.parser.AstValue.getValue(AstValue.java:123)
org.apache.el.parser.AstEqual.getValue(AstEqual.java:37)
The same error using HQL:
Code:
public List<Imovel> listaVenda() {
Query query = this.session.
createQuery("from House h, Modality m where h.avatar.id is not null and m.typeModality = 'Sale' order by h.dateInclusion desc");
return query.list();
}
Does anyone know if this is bug?
Thanks!