0

I'm trying to build a query on the fly from a custom query object.

At one point in the code, the orderBy may be added to a DetachedCriteria. Later down the line, I'd like to add an orderBy should none already exist in the DetachedCriteria. Looking through the docs, I can't seem to find any way to access this information.

Is there some way to do this?

(Of course if it's impossible, I'll just refactor my code around this)

gwcoderguy
  • 392
  • 1
  • 13

1 Answers1

1

Can you try this :

    DetachedCriteria detached; //intialized DetachedCriteria
    Session s; //intialized hibernate session

    //get the criteriaImpl executing the query 
    CriteriaImpl executableCriteria = (CriteriaImpl) detached.getExecutableCriteria(s);

    //return new iterator of the OrderEntries
    Iterator<CriteriaImpl.OrderEntry> orderEntryIterator = executableCriteria.iterateOrderings();

    //check if it has an order entry
    if (orderEntryIterator.hasNext()) {

    }

Hope it will help.

Andrianekena Moise
  • 1,018
  • 7
  • 16
  • Hm... I don't have access to the session at the point where I'm building the query unfortunately, so not sure this can work for my use-case. Good suggestion though! – gwcoderguy Feb 27 '19 at 00:09