Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.0.5
Is there a way to embed an HQL subquery within a Criteria query? The subquery needs to be in HQL because of the way my table associations are set up, but I want to be able to take advantage of the criteria api for the outer query. It seems like the Subqueries class only allows for subqueries in the criteria format.
One workaround would be something like this:
Code:
String queryString = "SELECT doc.documentId FROM " +
"Document doc, " +
"Archive archive, " +
"Audit audit " +
"where doc.archiveId = archive.archiveId " +
"and archive.archiveId = audit.archive.archiveId " +
"and audit.action.code = :actionCode " +
Query query = getSession().createQuery(queryString);
query.setString("actionCode", Constants.ACTION_SUBMIT);
subQueryList = query.list();
criteria.add(Restrictions.in("documentId", subQueryList));
However, this results in two calls to the database (One when query.list() is called and one when criteria.list() is called. Ideally I would like to execute it as a single query. I looked at the org.hibernate.criterion.Subqueries
class but it seems to only support subqueries that are also built using the criteria api.
Is there any other way to do this?