I have an SQL query that I would like to convert into a criteria (Hibernate 3.3.2) to use it into my persistancy layer. That's the query :
select last_name
from member
where
member.end_date > SYSDATE
group by member.last_name
having count(member.last_name) >1;
I already try a lot a combinations, but there is no result that would be good for me ... This is my code :
Criteria criteria = getSession(false).createCriteria(Member.ENTITY_NAME);
criteria.setProjection(Projections.projectionList()
.add(Projections.groupProperty("lastName"))
.add(Projections.count("lastName").as("cptLastName"))
);
criteria.add(Restrictions.ge("endDate", now))
.add(Restrictions.le("startDate", now))
//.add(Restrictions.gt("cptLastName", new Integer(1)))
.addOrder(Order.asc("lastName"))
;
With writing it with the comment line, I have an objects list that contains the name and the number of times that the name appears in the database. But when i would like to decomment it, this the error : java.sql.SQLException: ORA-00904: "Y1_": invalid identifier
To develop this code, I am inspired by different post below:
I think I'm not far of the solution but is there anybody to help me? If you have questions, don't hesitate to ask me it. And if you found another workaround for me to paste to this query, don't hesitate to propose it...