将寄存器Function和寄存器Hibernate类型迁移到Hibernate 6

eoxn13cs  于 2022-11-30  发布在  其他
关注(0)|答案(1)|浏览(187)

我正在尝试从Hibernate 5迁移到Hibernate 6,但遇到了以下代码:

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)
    }
}

看起来registerFunctionregisterHibernateType已经被移除了,它们的替换并不是微不足道的。有没有办法简单地解决这个问题呢?
编辑:我添加了进口以进行澄清。

bihw5rsg

bihw5rsg1#

第二部分可按如下方式处理:

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 );
    }
}

相关问题