user2366521
user2366521

Reputation: 39

Spring data jpa order by is not working when column value is having tab

I am using CrudRepository and generating an select query by method name For Ex:- findByPurposeOrderByProductDescriptionAsc(String purose)

Due to data quality issue a product description column has tabs coming as part of value. Due to the tabs the generated query is not correctly producing the results.

Usually in SQL query we can use the trim function and the order by will work.

In JPA even if i trim the attribute it doesnt work because the trim only applies on the produced results.

While what i want is that trim function applies before order by applies so that i get an proper expected sorted results.

Any suggestions where this can be done?

I tried one thing is that I write the sorting on produced results but i want to do at spring framework level

Any suggestions on this?

Upvotes: 1

Views: 368

Answers (1)

user2366521
user2366521

Reputation: 39

I found the fix for it. I use @Formula to use database specific function and it worked.

Upvotes: 1

Related Questions