I'm using a JPQL select to access a Oracle DB function: select FUNCTION('function_name', 'foo', 1234) from com_mycompany_bar obj
This works as expected and the function is indeed called. The thing is I actually don't need the FROM
clause and would rather have it empty instead of having to access an entity just to conform to the syntax.
What is the best option I have here?
I see several possible answers:
Within standard JPA there are two options, both involving Oracle
DUAL
"table"DUAL
to an entity and use it in theFROM
clause. It is the more "JPQL" way, but it is more involved:In Java code:
In orm.xml:
In client code:
DUAL
In orm.xml:
In client code:
As a last option, you can use some JPA implementation extension to JPA and avoid
DUAL
:Eclipselink:
Hibernate:
In short: I don't think it's possible to skip FROM clause of JPQL query.
JPQL grammar requires FROM clause to be present (see e.g. here or here).
Calling stored procedures/functions is typically done via native queries (see: createNativeQuery). So this should work:
UPDATE (from comments):
That's true that JPA native queries don't support named parameters. So you must decide which is the lesser of two evils for you: either using JPQL with unnecessary entity reference or native query with positional parameters instead of named.
But be aware that FUNCTION is EclipseLink extension so it won't work should you decide to change a vendor.