db2 如何禁用Hibernate SequenceInformation提取

mgdq6dx1  于 2022-11-07  发布在  DB2
关注(0)|答案(1)|浏览(214)

我使用的是Java/Quarkus版本1.13.7.Final和DB2数据库。
是否可以禁用Hibernate SequenceInformation提取?
This post显示在Spring中,可以使用以下参数完成:

spring.jpa.hibernate.use-new-id-generator-mappings=false

我手动生成我的ID,在这方面不需要Hibernate帮助。
在我的应用程序启动时,我收到了这个错误,因为我的数据库用户没有访问DB2 SEQUENCE表的权限:

11:28:05 ERROR [or.hi.en.jd.en.in.JdbcEnvironmentImpl] (Quarkus Main Thread)  Could not fetch the SequenceInformation from the database: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-551, SQLSTATE=42501, SQLERRMC=DB2MY-USER;SELECT;SYSCAT.SEQUENCES, DRIVER=4.27.25
    at com.ibm.db2.jcc.am.b7.a(b7.java:810)
    at com.ibm.db2.jcc.am.b7.a(b7.java:66)
    at com.ibm.db2.jcc.am.b7.a(b7.java:140)
    at com.ibm.db2.jcc.am.k6.c(k6.java:2825)
    at com.ibm.db2.jcc.am.k6.a(k6.java:2262)
    at com.ibm.db2.jcc.t4.ab.r(ab.java:1659)
    at com.ibm.db2.jcc.t4.ab.l(ab.java:756)
    at com.ibm.db2.jcc.t4.ab.d(ab.java:112)
    at com.ibm.db2.jcc.t4.p.c(p.java:44)
    at com.ibm.db2.jcc.t4.av.j(av.java:162)
    at com.ibm.db2.jcc.am.k6.an(k6.java:2257)
    at com.ibm.db2.jcc.am.k6.a(k6.java:3334)
    at com.ibm.db2.jcc.am.k6.a(k6.java:738)
    at com.ibm.db2.jcc.am.k6.executeQuery(k6.java:717)
    at org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl.extractMetadata(SequenceInformationExtractorLegacyImpl.java:42)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentImpl.sequenceInformationList(JdbcEnvironmentImpl.java:403)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentImpl.<init>(JdbcEnvironmentImpl.java:268)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:114)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:107)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:246)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
    at org.hibernate.boot.internal.SessionFactoryOptionsBuilder.<init>(SessionFactoryOptionsBuilder.java:265)
    at io.quarkus.hibernate.orm.runtime.recording.PrevalidatedQuarkusMetadata.buildSessionFactoryOptionsBuilder(PrevalidatedQuarkusMetadata.java:69)
    at io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.build(FastBootEntityManagerFactoryBuilder.java:71)
    at io.quarkus.hibernate.orm.runtime.FastBootHibernatePersistenceProvider.createEntityManagerFactory(FastBootHibernatePersistenceProvider.java:67)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:80)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
    at io.quarkus.hibernate.orm.runtime.JPAConfig$LazyPersistenceUnit.get(JPAConfig.java:118)
    at io.quarkus.hibernate.orm.runtime.JPAConfig.startAll(JPAConfig.java:42)
    at io.quarkus.hibernate.orm.runtime.JPAConfig_Subclass.startAll$$superaccessor6(JPAConfig_Subclass.zig:876)
    at io.quarkus.hibernate.orm.runtime.JPAConfig_Subclass$$function$$6.apply(JPAConfig_Subclass$$function$$6.zig:29)
    at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:62)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:51)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(InvocationInterceptor_Bean.zig:521)
    at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
    at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
    at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
    at io.quarkus.hibernate.orm.runtime.JPAConfig_Subclass.startAll(JPAConfig_Subclass.zig:834)
    at io.quarkus.hibernate.orm.runtime.HibernateOrmRecorder.startAllPersistenceUnits(HibernateOrmRecorder.java:88)
    at io.quarkus.deployment.steps.HibernateOrmProcessor$startPersistenceUnits951856026.deploy_0(HibernateOrmProcessor$startPersistenceUnits951856026.zig:74)
    at io.quarkus.deployment.steps.HibernateOrmProcessor$startPersistenceUnits951856026.deploy(HibernateOrmProcessor$startPersistenceUnits951856026.zig:40)
    at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:948)
    at io.quarkus.runtime.Application.start(Application.java:90)
    at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:100)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:66)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:42)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:119)
    at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:29)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at io.quarkus.runner.bootstrap.StartupActionImpl$3.run(StartupActionImpl.java:134)
    at java.base/java.lang.Thread.run(Thread.java:829)

我的表是这样的:

import java.io.Serializable;
import java.time.LocalDateTime;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Table;

@Entity
@Table(name = "DB2MYUSER.MY_ENTITY")
@IdClass(MyEntity.MyEntityPK.class)
public class MyEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    public static class MyEntityPK implements Serializable {
        public long codigoClienteParticipanteOpb;
        public int numeroSequencialBaseCalculo;
    }

    @Id
    @Column(name = "CD_CLI")
    private long client;

    @Id
    @Column(name = "SEQ")
    private int sequenceNumber;

    @Column(name = "TS_ATL")
    private LocalDateTime timestampAtualization;
}

Quarkus抱怨这个错误,但是我的应用程序启动了。但是,无论如何,我想删除这个错误消息。

hujrc8aj

hujrc8aj1#

您可以通过以下方式覆盖Hibernate方言中的方法getSequenceInformationExtractor

import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNoOpImpl;
import org.hibernate.dialect.DB2Dialect;

public class YourDialect extends DB2Dialect {

    // ...
    @Override
    public SequenceInformationExtractor getSequenceInformationExtractor() {
        return SequenceInformationExtractorNoOpImpl.INSTANCE;
    }
}

然后在Quarkus应用程序配置中使用此方言:

quarkus.hibernate-orm.dialect=your.app.package.YourDialect

相关问题