Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have spent some time on this and found a solution by extendeding a class CustomOrder.java from Order.java and override the toString() method as below:</p> <pre><code>public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { String[] columns = criteriaQuery.getColumnsUsingProjection(criteria, propertyName); Type type = criteriaQuery.getTypeUsingProjection(criteria, propertyName); StringBuffer fragment = new StringBuffer(); for (int i = 0; i &lt; columns.length; i++) { SessionFactoryImplementor factory = criteriaQuery.getFactory(); fragment.append("customOrder"); fragment.append("("); boolean lower = ignoreCase &amp;&amp; type.sqlTypes(factory)[i] == Types.VARCHAR; if (lower) { fragment.append(factory.getDialect().getLowercaseFunction()) .append('('); } fragment.append(columns[i]); if (lower) fragment.append(')'); fragment.append(")"); fragment.append(ascending ? " asc" : " desc"); if (i &lt; columns.length - 1) fragment.append(", "); } return fragment.toString(); } </code></pre> <p>then we need to call :</p> <pre><code>criteria.addOrder(CustomOrder.asc("name")); </code></pre> <p>instead of calling criteria.addOrder(Order.asc("name"))</p> <p>this worked and i was able to place DB method call in where clause as </p> <pre><code>select * from mytable order by customSort(name) asc; </code></pre> <p>I am just wondering is there a similar way such that i can place this function call in select part also using criteria?? for example:</p> <pre><code>select customSort(col1), col2, col3 from mytable order by customSort(name) asc; </code></pre> <p>pelase post your suggestions. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload