OscarSan
OscarSan

Reputation: 463

calling a custom function in a hibernate named query

I'm trying to call a function in a named query, but im getting :

java.lang.IllegalStateException: No data type for node:     org.hibernate.hql.ast.tree.MethodNode 
 \-[METHOD_CALL] MethodNode: '('
    +-[METHOD_NAME] IdentNode: 'MYFUNCTION' {originalText=MYFUNCTION}
    \-[EXPR_LIST] SqlNode: 'exprList'
       \-[NUM_INT] LiteralNode: '1'

and my query is something like

@NamedQuery(name = "myQuery",
            query = " select r, MYFUNCTION(r.id) from ResPO r "
                + " where  r.status like 'A'")

If I simplify my query, all is ok:

@NamedQuery(name = "myQuery",
        query = " select r from ResPO r "
            + " where  r.status like 'A'")

What is the mistake? Thanks++

Upvotes: 0

Views: 1566

Answers (1)

toniedzwiedz
toniedzwiedz

Reputation: 18553

You can do it by extending the dialect you're using and registering your function by calling the registerFunction() method.

http://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/dialect/Dialect.html#registerFunction%28java.lang.String,%20org.hibernate.dialect.function.SQLFunction%29

Upvotes: 1

Related Questions