Hibernate 6 QuarkusH2方言寄存器已删除功能

ca1c2owp  于 2023-08-06  发布在  其他
关注(0)|答案(1)|浏览(112)

我正在使用Quarkus和Hibernate。有一个扩展QuarkusH2Dialect的自定义类。但迁移到Hibernate 6后,它就不再工作了。它被移除了。你能提供一些建议,如何修复它?

import io.quarkus.hibernate.orm.runtime.dialect.QuarkusH2Dialect
import org.hibernate.dialect.function.SQLFunction
import org.hibernate.engine.spi.Mapping
import org.hibernate.engine.spi.SessionFactoryImplementor
import org.hibernate.type.StringType
import org.hibernate.type.Type

class MyDialect : QuarkusH2Dialect() {

    init {
        registerFunction(
            "calculate_hash",
            object : SQLFunction {
                override fun hasArguments() = true
                override fun hasParenthesesIfNoArguments() = false
                override fun getReturnType(firstArgumentType: Type?, mapping: Mapping?) = StringType.INSTANCE
                override fun render(firstArgumentType: Type?, arguments: List<Any?>?, factory: SessionFactoryImplementor?) =
                    "hash('calculate_hash', ${arguments?.first()})"
            }
        )
    }
}

字符串

hs1ihplo

hs1ihplo1#

扩展org.hibernate.dialect.H2Dialect
或者,更好的方法是通过自定义的MetadataBuilderContributor注册函数:

quarkus.hibernate-orm.metadata-builder-contributor=com.acme.MyMetadataBuilderConstributor

个字符
标签:https://github.com/quarkusio/quarkus/issues/32936

相关问题