Home > Mobile >  Is there any alternatives to registerColumnType on upgrade from Hibernate-core:5.6.10.Final to 6.1.5
Is there any alternatives to registerColumnType on upgrade from Hibernate-core:5.6.10.Final to 6.1.5

Time:12-02

I am currently upgrading from Spring-boot-starter-parent 2.7.3 to 3.0.0. The hibernate-core dependency for this is 6.1.5.Final.

This has broken my custom SQL dialect I had implemented.

The server dialect class is below:

public class ServerDialect extends SQLServer2012Dialect {

    public ServerDialect() {
        super();
        registerColumnType(Types.NVARCHAR, "nvarchar(max)");
        registerHibernateType(Types.NVARCHAR, StandardBasicTypes.STRING.getName());
    }
}

Since upgrade, these method's can no longer be resolved.

All I have changed is:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.3</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

to

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.0.0</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

I have looked up the documentation and searched for alternatives with no success.

CodePudding user response:

It might be worth evaluating if this Dialect is required for your project post upgrade - prior to Hibernate 6 it was common to provide the Dialect version via the hibernate.dialect setting, but it is no longer the recommended strategy. More information on this can be found in the documentation.

If this is not a suitable resolution, there is however a workaround for your issue.

SQLServer2012Dialect is now deprecated so as part of this migration should should consider refactoring your custom dialect to use the recommended SQLServerDialect.

You should be able to make use of resolveSqlTypeDescriptor to achieve the same or similar functionality - for example;

@Override
public JdbcType resolveSqlTypeDescriptor(String columnTypeName,
                                         int jdbcTypeCode,
                                         int precision,
                                         int scale,
                                         JdbcTypeRegistry jdbcTypeRegistry) {

    switch (jdbcTypeCode) {
        case Types. NVARCHAR, Types.CHAR -> jdbcTypeCode = StandardBasicTypes.STRING.getSqlTypeCode();
        // ETC
    }

    return super.resolveSqlTypeDescriptor(
            columnTypeName,
            jdbcTypeCode,
            precision,
            scale,
            jdbcTypeRegistry
    );
}

However, given your example above - this should not be required as the newer Hibernate should automatically perform an NVARCHAR mapping like this for you.

  • Related