Hello,
I would like to use hibernate as an persistence layer of my Forum. I use the Criterions and Criterias to build queries, but i don't know, how can I make a subquery with these components.
I would like change the following section with using criterions
Code:
try {
Session sess = HibernateSession.currentSession();
String querystring = "from Usr as usr where usr.usrloginname in ( " +
" select distinct message.usr.usrloginname from Message as message where " +
" message.creationdate between :startdate and :enddate ) ";
Query q = sess.createQuery(querystring);
Date startdate = new GregorianCalendar(2003, 2, 18).getTime();
Date enddate = new GregorianCalendar(2003, 2, 29).getTime();
q.setParameter("startdate", startdate);
q.setParameter("enddate", enddate);
Iterator it = q.iterate();
while (it.hasNext()) {
Usr usr = (Usr)it.next();
log.info(usr.getUsrloginname());
}
} catch (Exception e) {
log.error(e);
} finally {
try {
HibernateSession.closeSession();
} catch (Exception e) {
log.error(e);
}
}
Thx,
Kincza