Hello world !
I'm using Hibernate core 3.3.2GA with Hibernate annotations 3.4.0.GA. I have a Team Entity with 2 attributes, city and nickname. I want so search my Teams with a concatenation of both fields, for example "Los Angeles Lakers". I guess I can use @Formula for this but it doesn't work.
Code:
@Entity
@XmlRootElement(name = "team")
public class Team
{
private String nickname;
private String city;
@Formula(value = "CONCAT(city,\" \",nickname)")
private String cityAndNickname;
@Column
public String getCity()
{
return city;
}
@Column
public String getNickname()
{
return nickname;
}
...
}
I have tried different things, but when I query my db
Code:
Criteria criteria=sessionFactory.getCurrentSession().createCriteria(Team.class);
criteria.add(Restrictions.eq("cityAndNickname", teamCityPlusNickname));
I get the error "could not resolve property: cityAndNickname"
Any idea of what is wrong here ?
Thanks
--
Vincent