# Custom function in Hibernate 6.x from 5.3

**URL:** <https://discourse.hibernate.org/t/custom-function-in-hibernate-6-x-from-5-3/8016>\
**Category:** Hibernate ORM\
**Created:** [July 25, 2023, 9:51am UTC](https://discourse.hibernate.org/t/custom-function-in-hibernate-6-x-from-5-3/8016 "2023-07-25T09:51:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mv339](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mv339/32/3106_2.png) [@mv339](https://discourse.hibernate.org/u/mv339)\
**Post date:** [July 25, 2023, 9:51am UTC](https://discourse.hibernate.org/t/custom-function-in-hibernate-6-x-from-5-3/8016/1 "2023-07-25T09:51:18Z")

</div>

Hello,  
I’d like to ask a question regarding moving from hibernate-core 5.3.6 (hibernate-entitymanager,hibernate-java8) to the new hibernate-core 6.x.

I have old custom functions which use old **registerFunction** calls and are extending from **PostgreSQL9Dialect/H2Dialect**.  
I replaced the code to this by overriding **initializeFunctionRegistry(FunctionContributions functionContributions)** and registering my functions there.

But I have still problem with the code extending StandardSQLFunction. It goes like this:

```java
package sk.mindit.commons.persistence;

import org.hibernate.dialect.function.StandardSQLFunction;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.type.Type;

import java.util.List;
import java.util.stream.Collectors;

public class AclComputeFunction extends StandardSQLFunction {
    public AclComputeFunction(String name) {
        super(name);
    }

    public AclComputeFunction(String name, Type registeredType) {
        super(name, registeredType);
    }

    @Override
    public String render(Type firstArgumentType, List arguments, SessionFactoryImplementor sessionFactory) {
        return super.render(firstArgumentType, (List) arguments.stream()
                .map(s -> "(" + s + ")::bit(12)")
                .collect(Collectors.toList()), sessionFactory);
    }
}

```

I’d really like to have a simple way how to rewrite this code, I know that know there’s this function:

`render(SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArguments, SqlAstTranslator<?> translator)`

But overriding it seems like an overkill. Is there a simple (safe) way how to write this, or could you please point me to some examples ?

Thanks.

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [July 25, 2023, 11:26am UTC](https://discourse.hibernate.org/t/custom-function-in-hibernate-6-x-from-5-3/8016/2 "2023-07-25T11:26:14Z")

</div>

It’s not an overkill, you just need to call `append` on the `SqlAppender` e.g.

```java
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArguments, SqlAstTranslator<?> translator) {
    sqlAppender.append('(');
    sqlAstArguments.get(0).accept(translator);
    sqlAppender.append(")::bit(12)");
}

```

---

<div class="post-metadata">

**Author:** ![mv339](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mv339/32/3106_2.png) [@mv339](https://discourse.hibernate.org/u/mv339)\
**Post date:** [July 25, 2023, 11:55am UTC](https://discourse.hibernate.org/t/custom-function-in-hibernate-6-x-from-5-3/8016/3 "2023-07-25T11:55:35Z")

</div>

Hm, ok I’ll try it. I thought it’d be harder 🙂
