JPA Multilingual Sort

I am working on a bilingual project recently and for some reference tables I need to sort the data. But since it is bilingual, the data comes from different languages ​​(in my case English and French) and I like to sort them all together, for example Île

precedes Inlet

.

Normal Order By

will place Île

at the end of the list. I finally came up with the idea of ​​using nativeQuery

and sorting the data with the database engine function (in oracle used NLS_SORT

)

But I am very concerned with the engine and database version, so for example if I change my database to postgres

then the application breaks. I was looking for a native JPA solution (if exists) or any other solutions.

+3


source to share


1 answer


To archive this, without using the native query JPA definition, I just see two ways:

  • Create a DB view that includes escaped / translated columns based on DB functions. So the differences in the DB will be in the proposal create view

    . You can define the property of the OneToOne relationship to the original object.
  • Create an additional column that stores escaped values ​​and sorts by it. The application can escape / translate before storing data in the DB using JAA Entity Listeners or persist / merge methods.


Good luck!

+3


source







All Articles