0

I have a custom created function in postgres , now i'm trying to call the custom method from my code. here is the repository function


    @Query(value = "select function('createCluster',:tName,:time,:iPattern)")
    boolean createClusterIndex(@Param("tName") String tableName, @Param("iPattern") String indexPattern, @Param("time") LocalDateTime time);

going from this link https://thorben-janssen.com/database-functions/

i even registered by function in postgres dialect

this.registerFunction("createcluster",new StandardSQLFunction("createCluster",new BooleanType()));

but once i run the code

Caused by: org.hibernate.QueryException: No data type for node: org.hibernate.hql.internal.ast.tree.MethodNode 
 \-[METHOD_CALL] MethodNode: 'function (createCluster)'
    +-[METHOD_NAME] IdentNode: 'createCluster' {originalText=createCluster}
    \-[EXPR_LIST] SqlNode: 'exprList'
       +-[NAMED_PARAM] ParameterNode: '?' {name=tName, expectedType=null}
       +-[NAMED_PARAM] ParameterNode: '?' {name=time, expectedType=null}
       \-[NAMED_PARAM] ParameterNode: '?' {name=iPattern, expectedType=null}

    at org.hibernate.hql.internal.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:161) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final]
    at org.hibernate.hql.internal.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:1018) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final]
    at org.hibernate.hql.internal.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:786) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final]
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:677) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final]
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:313) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final]
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:261) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final]
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:271) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final]
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:191) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final]
    ... 106 common frames omitted
    

what could be the cause of this? how can i resolve this?

questions i have gone through:

Using Spring JPA to setup a Aggregate Function for STRING_AGG with Postgresql for a Group_By

No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode HQL

Write & Call user-defined function in JPQL?

User defined PostgreSQL function in hibernate dialect throws exception

1 Answer 1

0

Just use a native query. @Query(value = "select createCluster(:tName,:time,:iPattern)", nativeQuery = true

Sign up to request clarification or add additional context in comments.

3 Comments

i want avoid using native query
Avoiding the native query doesn't buy you anything as this is a database specific function I suppose? Anyway, you can avoid that by also adding a FROM clause to the query. Hibernate requires a FROM clause.
a custom function is part of almost every RDBMS Db , but i'm not sure about No-Sql , also the links i added are all indicating that it should be possible. finally i did try the FROM part , but it did not work either

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.