Tuesday, November 5, 2013

Using native database functions in JPQL


Share at Facebook

Java Persistence Query language(JPQL) is defined by the Java Persistence API(JPA) and it is very easy to use for querying database with entities. But sometime it becomes pretty hard to find similar function in JPQL which is available only in a particular database. To overcome this issue, it has an option and it is the FUNC function of JPQL.


This function basically interpret the database native functions with the JPQL. The procedure to use the function is like below.


FUNC('SOME_NATIVE_FUNCTION', 'PARAMETER'); FUNC('SOME_NATIVE_FUNCTION', 'PARAMETER_1', PARAMETER_2, 'PARAMETER_3');



I am using the TO_NUMBER() as an example here, but it can be any function.

SELECT o FROM result o WHERE FUNC('TO_NUMBER', e.total) < 90





No comments: