18

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?

3
  • Wouldn't this article answer your question ? Commented Apr 10, 2014 at 9:46
  • yeah, i have gone through it lots of time. But it is little out dated based on the current version of querydsl. Commented Apr 10, 2014 at 9:51
  • My bad. Consider I haven't said anything then :-) Commented Apr 10, 2014 at 9:56

2 Answers 2

30

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)"));
Sign up to request clarification or add additional context in comments.

7 Comments

Wow.. what a coincidence timo.. i just saw and read slide.. you got it almost all in it i need to know.. thank you.. and i ll definitely try your suggestion..
@Timo I'm trying this but i receive an: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node
Nice one. And also is it possible to handle more functions (nested inner functions) in a single call?
so ... basically ... QueryDSL doesnt support typesafe functions although it would be possible to extract the types via @NamedStoredProcedureQuery. Thats sad.
Hi, @renanleandrof, have you solve the problem? I got the same error: unexpected AST node. My code: Expressions.booleanTemplate("FIND_IN_SET({0}, {1})", arg1, arg2)
|
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.