Hi I want to fetch the data form data base开发者_JAVA技巧 using hibernate Criteria API.
That data should be ordered by some column as number.
This column is defined as varchar in DB. But I have to fetch as numberic.
I am facing problem using criteria API as it is ordering like string onyly.
Ex: I am getting data like
9, 8, 7, 6, 5, 4, 3, 2, 1,10
but i want data as
10,9,8,7,6,5,4,3,2,1
Is there any Hibernate methods to covert varchar to number like convert("some column",int ) or cast("some column",int) ?
You can use Projections.Cast()
to do a cast(column as type)
.
.AddOrder(Projections.Cast(NHibernateUtil.Int32, Projections.Property("stringColumn"))
精彩评论