M.Topa M.Topa - 4 months ago 24
Java Question

HQL order by for two different fileds

I want to select data from Workflow table using order by.How to do so?

public Workflow getDocById(String id) {
Query queryWfManager = sessionfactory.getCurrentSession().createQuery("from Workflow where id =:id");
queryWfManager.setParameter("id", id);

Workflow wfManagerList = (Workflow) queryWfManager.list();
Query queryWfDetails = sessionfactory.getCurrentSession().createQuery("from WorkflowDetails where workflowCode =:workflowCode order by wfBlockId order by stepSeq");
queryWfDetails.setParameter("workflowCode", wfManagerList.getWorkflowCode());

List<WorkflowDetails> queryWfDetailList = queryWfDetails.list();
wfManagerList.setSteps(queryWfDetailList);
return wfManagerList;
}


Which One is correct Writing oreder by order by wfBlockId , stepSeq OR order by wfBlockId order by stepSeq?

public Workflow getDocById(String id) {
Query queryWfManager = sessionfactory.getCurrentSession().createQuery("from Workflow where id =:id");
queryWfManager.setParameter("id", id);

Workflow wfManagerList = (Workflow) queryWfManager.list();
Query queryWfDetails = sessionfactory.getCurrentSession().createQuery("from WorkflowDetails where workflowCode =:workflowCode order by wfBlockId , stepSeq");
queryWfDetails.setParameter("workflowCode", wfManagerList.getWorkflowCode());

List<WorkflowDetails> queryWfDetailList = queryWfDetails.list();
wfManagerList.setSteps(queryWfDetailList);
return wfManagerList;
}

Answer
 Query queryWfDetails = sessionfactory.getCurrentSession()
    .createQuery("FROM WorkflowDetails where workflowCode =:workflowCode ORDER BY wfBlockId , stepSeq"); 

The above query is correct.

Comments