# registerFunction migration to Hibernate 6

**URL:** <https://discourse.hibernate.org/t/registerfunction-migration-to-hibernate-6/9441>\
**Category:** Hibernate ORM\
**Created:** [April 30, 2024, 11:36am UTC](https://discourse.hibernate.org/t/registerfunction-migration-to-hibernate-6/9441 "2024-04-30T11:36:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![GouthamSuda](https://avatars.discourse-cdn.com/v4/letter/g/a698b9/32.png) [@GouthamSuda](https://discourse.hibernate.org/u/GouthamSuda)\
**Post date:** [April 30, 2024, 11:36am UTC](https://discourse.hibernate.org/t/registerfunction-migration-to-hibernate-6/9441/1 "2024-04-30T11:36:00Z")

</div>

Hello,

Need help migrating to Hibernate 6.x and below is what I have in Hibernate 5.x :

```auto
public class CustomOracle10Dialect extends Oracle10gDialect {
    public CustomOracle10Dialect() {
        super();
        // SINGLE_COLUMN_FROM_JSON_TABLE function used to replace large in condition for Oracle
        registerFunction(SelectSingleColumnFromJsonTableOracleFunction.JSON_TABLE_FN_NAME,
                new SelectSingleColumnFromJsonTableOracleFunction());
    }
}

```

SelectSingleColumnFromJsonTableOracleFunction implements SQLFunction, overrides below -

```auto
   @Override
    public Type getReturnType(Type firstArgumentType, Mapping mapping) throws QueryException {
        return new CustomCollectionType(SingleFieldCollectionType.class, "", "");
    }

    @Override
    @SuppressWarnings({"rawtypes", "unchecked"})
    public String render(Type firstArgumentType, List arguments, SessionFactoryImplementor factory) throws QueryException {
        return transformArgsToJsonFnQueryStub((List<Object>)arguments);
    }

```

transformArgsToJsonFnQueryStub returns a string of StringBuilder.

@beikov Tagging you here as I have seen many of your replies to similar posts.

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [April 30, 2024, 12:13pm UTC](https://discourse.hibernate.org/t/registerfunction-migration-to-hibernate-6/9441/2 "2024-04-30T12:13:15Z")

</div>

Hello, to register custom functions you should create custom a `org.hibernate.boot.model.FunctionContributor` and provide it as a service in your application by creating a file `META-INF/services/org.hibernate.boot.model.FunctionContributor` that contains its fully qualified class name.

Also, since Hibernate 6 [version-specific dialects have been deprecated](https://docs.jboss.org/hibernate/orm/6.0/migration-guide/migration-guide.html#version-specific-and-spatial-dialects), so I would suggest using `org.hibernate.dialect.OracleDialect`.

---

<div class="post-metadata">

**Author:** ![GouthamSuda](https://avatars.discourse-cdn.com/v4/letter/g/a698b9/32.png) [@GouthamSuda](https://discourse.hibernate.org/u/GouthamSuda)\
**Post date:** [April 30, 2024, 12:33pm UTC](https://discourse.hibernate.org/t/registerfunction-migration-to-hibernate-6/9441/3 "2024-04-30T12:33:46Z")

</div>

While I try the suggested, how can I register my custom SelectSingleColumnFromJsonTableOracleFunction with custom return i.e. CustomCollectionType ?

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [April 30, 2024, 12:46pm UTC](https://discourse.hibernate.org/t/registerfunction-migration-to-hibernate-6/9441/4 "2024-04-30T12:46:22Z")

</div>

If you want more control on the return type of your custom function you can extend `AbstractSqmSelfRenderingFunctionDescriptor`, and pass a `FunctionReturnTypeResolver` (e.g. one of Hibernate’s `StandardFunctionReturnTypeResolvers`) according to what you need.

Note, however, that `org.hibernate.type.CustomCollectionType` does not implement `ReturnableType`, so I doubt that’s the correct type that you want. I suggest looking into what your function actually returns, you probably want to use `CustomType` instead.

---

<div class="post-metadata">

**Author:** ![GouthamSuda](https://avatars.discourse-cdn.com/v4/letter/g/a698b9/32.png) [@GouthamSuda](https://discourse.hibernate.org/u/GouthamSuda)\
**Post date:** [April 30, 2024, 1:07pm UTC](https://discourse.hibernate.org/t/registerfunction-migration-to-hibernate-6/9441/5 "2024-04-30T13:07:21Z")

</div>

@mbladel Is there an example/sample that you could point me to ?

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [April 30, 2024, 1:15pm UTC](https://discourse.hibernate.org/t/registerfunction-migration-to-hibernate-6/9441/6 "2024-04-30T13:15:11Z")

</div>

You can look at any of the inheritor classes in Hibernate itself for examples. Also, you can look at `SqmFunctionRegistry` descriptor builders, maybe your custom function can be registered using one of those without the need of a custom implementation.
