I have a situation where I have to create dynamic sorting, so this purpose I am using criteria query in JPA (Using predicate and all), (I can not use NamedQuery just because if i have to provide multple ways of sorting I ahve to provide multiple comparators in Java which I do not want to prefer). Here I have to UNION two queries. Is there any way I could do? I know Hibernate and JPA does not support UNION.
Asked
Active
Viewed 1,759 times
0
-
You "know Hibernate and JPA does not support UNION", yet you ask is there a way in Hibernate or JPA. Sounds like a contradiction there. And "NamedQuery" is simply JPQL so no there is no possibility with NamedQuery. Perhaps you meant to say you cant use "NamedNativeQuery" – Neil Stockton Feb 28 '14 at 11:41
-
@Neil: It's contradiction but why I put this query because is there any solution based approach that I have not tried or thought. And yea I can not use named native query or any named query because I have to use order by clause in my query which depends upon user. Comparator I can not use because then I would have to provide n number fo comparators in my pojo class , which I do not want. – gahlot.jaggs Feb 28 '14 at 12:05
-
A union wouldn't solve your sorting problem either – Software Engineer Feb 28 '14 at 20:00
-
I didn't say UNION would be an option. The problem is : queri 1 is sorted on one column and query 2 is also sorted in same type of column, but if i execute them separately and add the result list to one another then i didn't get the final list as sorted list. SO there are two ways either I could implement comparator for my class and sort the final list but as I have to do the sorting dynamicly so i have to provide multiple comparators and that is not the goid solution. And other option is i should execute a single query which do UNION and i will get a single list which is sorted. I hope this w – Mar 02 '14 at 03:55
-
I didn't say UNION would be an option. The problem is : queri 1 is sorted on one column and query 2 is also sorted in same type of column, but if i execute them separately and add the result list to one another then i didn't get the final list as sorted list. SO there are two ways either I could implement comparator for my class and sort the final list but as I have to do the sorting dynamicly so i have to provide multiple comparators and that is not the goid solution. And other option is i should execute a single query which do UNION and i will get a single list which is sorted – gahlot.jaggs Mar 03 '14 at 12:11