| JPA 2.1 specification, section 4.6.17.3, describes the support for FUNCTION construct that allows me to call any function from DB. I tried that, but Hibernate 5.1.0 failed in two ways. For my tests I mapped DUAL table from H2, but that should not matter. For: {{ { select FUNCTION('random_uuid') from org.hibernate.bugs.model.Dual dual } }} It throws: {{ { java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: expecting COMMA, found ')' near line 1, column 30 [select FUNCTION('random_uuid') from org.hibernate.bugs.model.Dual dual] } }} Seems it cannot even parse it for no-arg functions, that's a grammar/parse problem. I tried something with an argument then: {{ { Object result = em.createQuery("select FUNCTION('random', 3) from Dual dual") .getSingleResult(); } }} And this failed with: {{{ java.lang.IllegalStateException: No data type for node: org.hibernate.hql.internal.ast.tree.MethodNode -[METHOD_CALL] MethodNode: 'FUNCTION (random)' +-[METHOD_NAME] IdentNode: 'random' {originalText=random} -[EXPR_LIST] SqlNode: 'exprList' -[NUM_INT] LiteralNode: '3' }}} From the point of JPA 2.1 spec I have no idea what I should do with this. I provide a Maven-based test case on https://github.com/virgo47/litterbin/tree/master/issues/hibernate-jpa21-function - this can be easily run from bash/cmd: {{ { svn export https://github.com/virgo47/litterbin/trunk/issues/hibernate-jpa21-function cd hibernate-jpa21-function mvn clear test } }} Both test should pass. As a cross-reference, I added dependency on EclipseLink. Just switch commented lines in src/main/resources/META-INF/persistence.xml to enable EclipseLink and re-run mvn. Both tests pass. I found nothing in the User docs (http://docs.jboss.org/hibernate/orm/5.0/userGuide/en-US/html_single). I believe section 13.4.8.3. Non-standardized functions is Hibernate specific and not JPA 2.1 standard. (From the rough check in the user doc, also JPA 2.1 TREAT seems to be unsupported, BTW.) |