Вопрос

I am in little hurry so, i just want to ask a quick question about querydsl. According to my research, query dsl doesn't support stored procedure but can support database functions. My Question is how can we invoke those database functions using querydsl?

Это было полезно?

Решение

You can use TemplateExpression based injections of arbitrary JPQL syntax into your query.

e.g.

query.where(Expressions.booleanTemplate("func1({0}, {1})", arg1, arg2));

If you use Hibernate 4.3 or any other JPA 2.1 compliant provider you can use the FUNCTION syntax to invoke SQL functions https://bugs.eclipse.org/bugs/show_bug.cgi?id=350843

So the example would turn into

query.where(Expressions.booleanTemplate("function('func1', {0}, {1})", arg1, arg2)"));

Другие советы

example of call mysql function find_in_set:

query.where(Expressions.booleanTemplate("find_in_set({0}, {1}) > 0", 1, "1,2,3"));

'> 0' Is a must, else thorw unexpected AST node

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top