Hello,
My problem is quite simple, I want to perform order on a field that is too big to be used for SQL ordering (more than 500 char). So I got some thing like [Error Code: -1013, SQL State: I1013] [-1013] (at 1021): Too many order columns.
One sql solution is to order by substr('myfield',0,20). (I don't know others)
Now I want to do that with criteria. I turn around criteria.addOder( Order....) and criteria.addOder( Property.asc(....)) But I can't find how to add this 'substr'.
Some of my conclusion:
- Going to SQL or HQL is not a solution for me.
- crit.addOrder(Order.asc("substr('nmowner', 0, 20)")); doesn't work
Thank you for your help!
Yoann.
Hibernate version: 3.1.3
Mapping documents:
Code:
<hibernate-mapping>
<class name="MyPackage.Owner" table="OWNER" schema="MYDB">
<id name="idowner" type="java.lang.Long">
<column name="IDOWNER" precision="10" scale="0" />
<generator class="increment" />
</id>
<property name="nmowner" type="java.lang.String">
<column name="NMOWNER" length="510" not-null="true" />
</property>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Criteria crit = session.createCriteria(Owner.class);
crit.add(Restrictions.like("nmowner", "%"));
crit.setFirstResult(1);
crit.setMaxResults(10);
crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
crit.addOrder(Order.asc("nmowner"));
List result = crit.list();
Full stack trace of any exception that occurs: [Error Code: -1013, SQL State: I1013] [-1013] (at 1021): Too many order columns
Name and version of the database you are using: MaxDB...
The generated SQL (show_sql=true):
select
this_.IDOWNER as IDOWNER93_0_,
this_.NMOWNER as NMOWNER93_0_
from
MYDB.OWNER this_
where
this_.IDOWNER < 10
order by
this_.NMOWNER asc
Debug level Hibernate log excerpt: