# Migration of dialect to Hibernate 6

**URL:** <https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956>\
**Category:** Hibernate ORM\
**Created:** [November 25, 2022, 8:16am UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956 "2022-11-25T08:16:21Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![knyttl](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/knyttl/32/2136_2.png) [@knyttl](https://discourse.hibernate.org/u/knyttl)\
**Post date:** [November 25, 2022, 8:16am UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956/1 "2022-11-25T08:16:21Z")

</div>

I am trying to migrate from Hibernate 5 to 6 and I am a bit stuck with following code:

```kotlin
import org.hibernate.dialect.MySQL57Dialect
import org.hibernate.dialect.function.SQLFunctionTemplate
import org.hibernate.dialect.function.StandardSQLFunction
import org.hibernate.type.StandardBasicTypes
import org.hibernate.type.StringType
import java.sql.Types

class CustomMySQLDialect : MySQLDialect(DatabaseVersion.make(5, 70)) {
    init {
        registerFunction("group_concat", StandardSQLFunction("group_concat", StringType()))
        registerFunction("match_against", SQLFunction(StandardBasicTypes.DOUBLE, "match (?1) against (?2 in boolean mode)"))

        registerHibernateType(Types.FLOAT, StandardBasicTypes.DOUBLE.name)
        registerHibernateType(Types.BIGINT, StandardBasicTypes.LONG.name)
        registerHibernateType(Types.TINYINT, StandardBasicTypes.LONG.name)
        registerHibernateType(Types.INTEGER, StandardBasicTypes.LONG.name)
        registerHibernateType(Types.DECIMAL, StandardBasicTypes.LONG.name)
    }
}

```

It seems that the `registerFunction` and `registerHibernateType` has been removed and their replacement is not trivial. Is there a way to od this simply?

---

<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:** [November 25, 2022, 8:52am UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956/2 "2022-11-25T08:52:26Z")

</div>

There is no easy way, but I think you don’t need `registerHibernateType` anymore. As for `registerFunction`, I’d suggest you rather introduce a `org.hibernate.boot.model.FunctionContributor`:

```java
public class MyFunctionContributor imlements org.hibernate.boot.model.FunctionContributor {
    public void contributeFunctions(FunctionContributions functionContributions) {
        functionContributions.getFunctionRegistry().registerAlternateKey("group_concat", "listagg");
        functionContributions.getFunctionRegistry().registerPattern("match_against", "match (?1) against (?2 in boolean mode)", functionContributions.getTypeConfiguration().getBasicTypeRegistry().resolve(StandardBasicTypes.DOUBLE));
    }
}

```

Note that you also need a file `META-INF/services/org.hibernate.boot.model.FunctionContributor` that contains the fully qualified class name of `MyFunctionContributor`.

---

<div class="post-metadata">

**Author:** ![knyttl](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/knyttl/32/2136_2.png) [@knyttl](https://discourse.hibernate.org/u/knyttl)\
**Post date:** [November 25, 2022, 10:45am UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956/3 "2022-11-25T10:45:44Z")

</div>

> [@beikov](#):
>
> but I think you don’t need `registerHibernateType` anymore

But I need this 🙂 I want to avoid fetching numbers from database as Short or Int and I want to always get Long.

---

<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:** [November 25, 2022, 11:11am UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956/4 "2022-11-25T11:11:43Z")

</div>

If you want to affect how native query results are materialized, you have to override the `Dialect#resolveSqlTypeDescriptor` method similar to this:

```java
public class MyDialect extends MySQLDialect {

//...

	public JdbcType resolveSqlTypeDescriptor(
			String columnTypeName,
			int jdbcTypeCode,
			int precision,
			int scale,
			JdbcTypeRegistry jdbcTypeRegistry) {
		
		switch ( jdbcTypeCode ) {
			case Types.FLOAT:
				jdbcTypeCode = Types.DOUBLE;
				break;
			case Types.TINYINT:
			case Types.INTEGER:
			case Types.DECIMAL:
				jdbcTypeCode = Types.BIGINT;
				break;
		}
		return super.resolveSqlTypeDescriptor( columnTypeName, jdbcTypeCode, precision, scale, jdbcTypeRegistry );
	}
}

```

---

<div class="post-metadata">

**Author:** ![knyttl](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/knyttl/32/2136_2.png) [@knyttl](https://discourse.hibernate.org/u/knyttl)\
**Post date:** [November 27, 2022, 7:37pm UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956/5 "2022-11-27T19:37:53Z")

</div>

This seems to help, thanks!

---

<div class="post-metadata">

**Author:** ![tugce](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/tugce/32/2588_2.png) [@tugce](https://discourse.hibernate.org/u/tugce)\
**Post date:** [July 26, 2023, 8:09am UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956/7 "2023-07-26T08:09:55Z")

</div>

Hi @beikov,

I upgraded Hibernate from 5.6 to 6.2 and I want to use FunctionContributor to use custom functions in my Hibernate queries. and I use `register` method like that:

```auto
@Override
	public void contributeFunctions(FunctionContributions functionContributions) {
		functionContributions.getFunctionRegistry().register("string_agg",
				new StandardSQLFunction("string_agg", StandardBasicTypes.STRING));

}

```

and I created the file `META-INF/services/org.hibernate.boot.model.FunctionContributor`. This file contains fully qualified class name. But somehow my custom function cannot be recognized. Can you help me out to understand what is wrong?

---

<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 26, 2023, 10:23am UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956/8 "2023-07-26T10:23:09Z")

</div>

> Can you help me out to understand what is wrong?

What you did is correct and it should work, but if it doesn’t, then maybe something is wrong with your environment or build. Either way, note that ORM 6.2 comes with the standard function called `listagg` that translates to `string_agg`. Also see [https://docs.jboss.org/hibernate/orm/6.2/userguide/html\_single/Hibernate\_User\_Guide.html#hql-aggregate-functions-orderedset](https://docs.jboss.org/hibernate/orm/6.2/userguide/html_single/Hibernate_User_Guide.html#hql-aggregate-functions-orderedset)

---

<div class="post-metadata">

**Author:** ![tugce](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/tugce/32/2588_2.png) [@tugce](https://discourse.hibernate.org/u/tugce)\
**Post date:** [July 26, 2023, 2:13pm UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956/9 "2023-07-26T14:13:27Z")

</div>

I found my mistake. I had to change usage of date parameter. Thanks for replying me.

---

<div class="post-metadata">

**Author:** ![Uday\_Patil](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/uday_patil/32/2640_2.png) [@Uday\_Patil](https://discourse.hibernate.org/u/Uday_Patil)\
**Post date:** [September 4, 2023, 11:29am UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956/10 "2023-09-04T11:29:25Z")

</div>

Hi @beikov,  
I have following custom dialect config in hibernate 5

```auto
  public Oracle12cCustomDialect() {
        super();
        this.registerHibernateType(2003, DecimalArrayType.class.getName());
    }

```

However, when I upgrade to hibernate 6 along with spring boot 3. I get the following error when I remove the above code.

```auto
java.lang.NullPointerException: Cannot invoke "String.hashCode()" because "this.typeName" is null
	at org.hibernate.dialect.OracleArrayJdbcType.hashCode(OracleArrayJdbcType.java:202)
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1694)
	at org.hibernate.type.BasicTypeRegistry.resolve(BasicTypeRegistry.java:192)
	at org.hibernate.type.BasicTypeRegistry.resolve(BasicTypeRegistry.java:160)
	at org.hibernate.sql.results.jdbc.internal.ResultSetAccess.resolveType(ResultSetAccess.java:146)

```

Can you help me resolve this ?  
It looks like I can’t use registerHibernateType anymore and without that this error occurs.

---

<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:** [September 4, 2023, 1:12pm UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956/11 "2023-09-04T13:12:25Z")

</div>

Read the migration guides. Hibernate 6 is not a drop-in replacement. You will have to adapt your code:

- [https://github.com/hibernate/hibernate-orm/blob/6.0/migration-guide.adoc](https://github.com/hibernate/hibernate-orm/blob/6.0/migration-guide.adoc)
- [https://github.com/hibernate/hibernate-orm/blob/6.1/migration-guide.adoc](https://github.com/hibernate/hibernate-orm/blob/6.1/migration-guide.adoc)
- [https://github.com/hibernate/hibernate-orm/blob/6.2/migration-guide.adoc](https://github.com/hibernate/hibernate-orm/blob/6.2/migration-guide.adoc)

---

<div class="post-metadata">

**Author:** ![Uday\_Patil](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/uday_patil/32/2640_2.png) [@Uday\_Patil](https://discourse.hibernate.org/u/Uday_Patil)\
**Post date:** [September 5, 2023, 11:32am UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956/12 "2023-09-05T11:32:41Z")

</div>

Hi @beikov,

I checked doc and also dug deep into codebase and it looks like a bug in hibernate.

For the column type MDSYS.SDO\_ORDINATE\_ARRAY which my query is returning, typeName field is being null from **org.hibernate.type.descriptor.jdbc.JdbcType.**  
Check the below snapshot from my debug session.

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/hibernate/original/2X/8/8070673e15990f23c71fc92886f50bcb7057867e.png)

And due to this reason I am getting following error

```auto
java.lang.NullPointerException: Cannot invoke "String.hashCode()" because "this.typeName" is null
	at org.hibernate.dialect.OracleArrayJdbcType.hashCode(OracleArrayJdbcType.java:202)
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1694)
	at org.hibernate.type.BasicTypeRegistry.resolve(BasicTypeRegistry.java:192)
	at org.hibernate.type.BasicTypeRegistry.resolve(BasicTypeRegistry.java:160)
	at org.hibernate.sql.results.jdbc.internal.ResultSetAccess.resolveType(ResultSetAccess.java:146)

```

If it’s a bug as I suspect it is, let me know where can I raise this bug issue ?  
Thanks in advance !!

---

<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:** [September 5, 2023, 1:16pm UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956/13 "2023-09-05T13:16:40Z")

</div>

You seem to be using a custom dialect, but this is not encouraged anymore. Please share the dialect contents.

---

<div class="post-metadata">

**Author:** ![Uday\_Patil](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/uday_patil/32/2640_2.png) [@Uday\_Patil](https://discourse.hibernate.org/u/Uday_Patil)\
**Post date:** [September 5, 2023, 1:41pm UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956/14 "2023-09-05T13:41:45Z")

</div>

You can ignore that it’s an empty class, contents are commented for that (It was required for hibernate version 5),

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/hibernate/original/2X/6/6dea705df45308170bdfbaf0b45ad504dbb68d00.png)

---

<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:** [September 5, 2023, 3:05pm UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956/15 "2023-09-05T15:05:18Z")

</div>

So you are running a native query that returns an Oracle “array”, though it seems `SDO_ORDINATE_ARRAY` is rather a spatial type.  
I guess we are simply missing a translation from that type to the `SqlTypes` constants in `resolveSqlTypeDescriptor`, similar to what we already do for `MDSYS.SDO_GEOMETRY` in `OracleDialect#resolveSqlTypeDescriptor`. Can you explain to me what this `SDO_ORDINATE_ARRAY` represents? How was this deserialized before? As `Geometry`?

---

<div class="post-metadata">

**Author:** ![Uday\_Patil](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/uday_patil/32/2640_2.png) [@Uday\_Patil](https://discourse.hibernate.org/u/Uday_Patil)\
**Post date:** [September 6, 2023, 7:08am UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956/16 "2023-09-06T07:08:05Z")

</div>

We were simply doing below and deserialization was taken care of for **SDO\_ORDINATE\_ARRAY**.  
_DecimalArrayType_ is coming from third party dependency.

```auto
this.registerHibernateType(2003, DecimalArrayType.class.getName());

```

```auto
        <dependency>
            <groupId>com.vladmihalcea</groupId>
            <artifactId>hibernate-types-52</artifactId>
            <version>2.11.1</version>
        </dependency>

```

> **Fully qualified class name:** _com.vladmihalcea.hibernate.type.array.DecimalArrayType_

And for collecting query results in Java, in our projection we were using **BigDecimal[] getOrdinates();** Snapshot below for the projection.

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/hibernate/original/2X/6/60f8e9e134f2894e5ce96096f6692222dc6af6ec.png)

Lastly, you can refer below doc for SDO\_ORDINATE\_ARRAY

> **[Spatial Developer's Guide](https://docs.oracle.com/en/database/oracle/oracle-database/21/spatl/spatial-datatypes-metadata.html#GUID-79D7620B-5526-40FD-9604-9642B79908F2)**
>
> The spatial features in Oracle Spatial consist of a set of object data types, type methods, and operators, functions, and procedures that use these types. A geometry is stored as an object, in a single row, in a column of type SDO\_GEOMETRY. Spatial...

---

<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:** [September 6, 2023, 7:57am UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956/17 "2023-09-06T07:57:54Z")

</div>

Please create an issue in the issue tracker([https://hibernate.atlassian.net](https://hibernate.atlassian.net)) for this feature request. It should be easy to support, but if you need a solution now, you’ll have to override the `resolveSqlTypeDescriptor` of your custom dialect, something like this:

```java
		if ( jdbcTypeCode == ARRAY && "MDSYS.SDO_ORDINATE_ARRAY".equals( columnTypeName ) ) {
			final JdbcTypeConstructor jdbcTypeConstructor = jdbcTypeRegistry.getConstructor( jdbcTypeCode );
			if ( jdbcTypeConstructor != null ) {
				return jdbcTypeConstructor.resolveType(
						jdbcTypeRegistry.getTypeConfiguration(),
						this,
						jdbcTypeRegistry.getDescriptor( SqlTypes.NUMERIC ),
						ColumnTypeInformation.EMPTY
				);
			}
		}

```

---

<div class="post-metadata">

**Author:** ![Uday\_Patil](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/uday_patil/32/2640_2.png) [@Uday\_Patil](https://discourse.hibernate.org/u/Uday_Patil)\
**Post date:** [September 6, 2023, 9:11am UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956/18 "2023-09-06T09:11:05Z")

</div>

Thank you very much !!! @beikov  
But Now, It’s throwing me this error after trying your solution.

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/hibernate/original/2X/6/6cd2c58d9f2c18748ef176d373851e35051d1cb0.png)

PS: I was on hibernate 6.1.5, In order to try your solution I upgraded hibernate to 6.3.0

---

<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:** [September 6, 2023, 10:27am UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956/19 "2023-09-06T10:27:52Z")

</div>

There is a bug in 6.3.0 which was already fixed, but we didn’t release 6.3.1 yet. Please try 6.2.8 for now.

---

<div class="post-metadata">

**Author:** ![Uday\_Patil](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/uday_patil/32/2640_2.png) [@Uday\_Patil](https://discourse.hibernate.org/u/Uday_Patil)\
**Post date:** [September 6, 2023, 10:45am UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956/20 "2023-09-06T10:45:42Z")

</div>

6.2.8 does not have JdbcTypeConstructor to use, Is there any other way can we configure this ?

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/hibernate/original/2X/0/06167b6254c1f6b7b896c34dcda01ea2f194fc42.png)

---

<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:** [September 6, 2023, 11:09am UTC](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956/21 "2023-09-06T11:09:58Z")

</div>

Yeah, you use this:

```java
		final JdbcType jdbcType = jdbcTypeRegistry.getDescriptor( jdbcTypeCode );
		if ( jdbcTypeCode == Types.ARRAY && "MDSYS.SDO_ORDINATE_ARRAY".equals( columnTypeName ) && jdbcType instanceof ArrayJdbcType ) {
			return ( (ArrayJdbcType) jdbcType ).resolveType(
					jdbcTypeRegistry.getTypeConfiguration(),
					this,
					jdbcTypeRegistry.getDescriptor( SqlTypes.NUMERIC),
					null
			);
		}

```

[Next page](https://discourse.hibernate.org/t/migration-of-dialect-to-hibernate-6/6956.md?page=2)
