HIBERNATE - JPA how can I pass a String containing an underscore to a CriteriaBuilder query?

Viewed 35

Unfortunately I'm not authorized to show any code. Also I'm sorry if I'm not giving enough info, this is my first time asking a question on this website. Please let me know if there's more you need to know.

I have a CriteriaBuilder query that sorts via Pageable. The sorting method as of right now sorts by entities' properties, however I want to sort by a field generated by a LISTAGG but every time I try to pass "col_12_0_" hibernate sees the underscore and only takes "col" as a value... How can I solve this?

I've tried using the .alias() method to generate the alias I want in the query but it seems like it's not working as CB always generates aliases such as "col_1_0_".

I've also tried setting the generation strategy as PhysicalNamingStrategyStandardImpl but nothing changes.

1 Answers

With Hibernate ORM's JPA Criteria implementation, this is only possible as of version 6. It should work with HQL also in Hibernate 5 though.

If you must use JPA Criteria, you will have to introduce another custom function, e.g. pass_through which accepts a string and renders the unquoted string to SQL. Then you can use that to render "any" SQL fragments you want.

Related