user1016403
user1016403

Reputation: 12621

applying to number and order by for a column of varchar type in hibernate using criteria?

I am using hibernate. i have below native sql query.

select * from some_table order by to_number(someId);

here someId column contains all numbers but datatype is of varchar type. so while pulling i need to apply order by. if order by is applied with out to_number then ASCII comparison is done. to avoid that i need to apply order by with to_number.

how can i achieve the same using criteria? i am not using annotations. using hbms.

Thanks!

Upvotes: 0

Views: 2763

Answers (1)

Mikko Maunu
Mikko Maunu

Reputation: 42114

That cannot be done with Criteria API, because it does not provide conversion from string to number (of for example from varchar to integer in the end).

You can:

  • Use Hibernate Criteria and this workaround.
  • Use HQL and cast if your database supports it: documentation

Upvotes: 1

Related Questions