JOOQ版本:3.15.3

我有一个jOOQ更新查询,它使用子查询来设置值:

myDslContext.update(TICKET)
    .set(TICKET.TICKET_STATUS, BillingStatus.POSTED)
    .set(TICKET.INVOICE, myDslContext.select(AR_INVOICE.INVOICE)
        .from(AR_INVOICE)
        .where(AR_INVOICE.CUSTID.eq(TICKET.CUSTID))
        .and(AR_INVOICE.STATUS.eq(BillingStatus.PRINTED)))
    .where(TICKET.INVOICE.isNull())
    .and(TICKET.TICKET_STATUS.eq(BillingStatus.PRINTED))
    .andExists(myDslContext.select(AR_INVOICE.INVOICE)
        .from(AR_INVOICE)
        .where(AR_INVOICE.CUSTID.eq(TICKET.CUSTID))
        .and(AR_INVOICE.STATUS.eq(BillingStatus.PRINTED)))
    .execute();

BillingStatus枚举使用自定义绑定.在实现jOOQ绑定接口时,必须编写代码来呈现SQL中的值.因此,我的代码判断上下文配置,如果SQLDialect不是预期的,则抛出异常.

@Override
public void sql(BindingSQLContext<T> ctx) throws SQLException {
  Short converted = converter().to(ctx.value());

  if (ctx.family() == SQLDialect.INFORMIX) {
    if (ctx.render().paramType() == ParamType.INLINED) {
      if (converted == null) {
        ctx.render().sql("NULL");
      } else {
        ctx.render().sql(String.valueOf(converted));
      }
    } else {
      ctx.render().sql(ctx.variable());
    }
  } else {
    throw new SQLFeatureNotSupportedException();
  }
}

然而,在子查询的上下文中,我看到BindingSQLContext配置使用方言DEFAULT,而不是预期的INFORMIX.我可以简单地删除方言判断,但在不久的将来,我们打算将此代码移动到不同的数据库,因此我感觉future 可能需要这样做.尽管我希望验证方言,但我仍然认为应该在这里正确设置方言,因为在其他情况下可能需要特定于方言的代码.

我使用静态DSLL.select()获得了相同的结果,而不是使用我配置的DSLContext myDslContext

我目前被困在jOOQ 3.15上,因为就目前而言,我们有其他阻止程序可以从Spring Boot2.x迁移到3.x,我们可以使用更新的jOOQ版本.

我做的子查询是完全错误的,还是这是一个bug?如果这是一个bug,有没有解决方法?

UPDATE:

以下是我失败的集成测试的完整堆栈跟踪:

org.jooq.exception.DataAccessException: Error while generating SQL for Binding

    at org.jooq.impl.Val.accept(Val.java:185)
    at org.jooq.impl.DefaultRenderContext.visit0(DefaultRenderContext.java:720)
    at org.jooq.impl.AbstractContext.visit(AbstractContext.java:296)
    at org.jooq.impl.AbstractContext.lambda$visit$2(AbstractContext.java:832)
    at org.jooq.impl.AbstractContext.toggle(AbstractContext.java:333)
    at org.jooq.impl.AbstractContext.paramType(AbstractContext.java:845)
    at org.jooq.impl.AbstractContext.visit(AbstractContext.java:832)
    at org.jooq.impl.CompareCondition.accept0(CompareCondition.java:214)
    at org.jooq.impl.CompareCondition.accept(CompareCondition.java:159)
    at org.jooq.impl.DefaultRenderContext.visit0(DefaultRenderContext.java:720)
    at org.jooq.impl.AbstractContext.visit(AbstractContext.java:296)
    at org.jooq.impl.CombinedCondition.accept(CombinedCondition.java:231)
    at org.jooq.impl.DefaultRenderContext.visit0(DefaultRenderContext.java:720)
    at org.jooq.impl.AbstractContext.visit(AbstractContext.java:296)
    at org.jooq.impl.ConditionProviderImpl.accept(ConditionProviderImpl.java:127)
    at org.jooq.impl.DefaultRenderContext.visit0(DefaultRenderContext.java:720)
    at org.jooq.impl.AbstractContext.visit(AbstractContext.java:296)
    at org.jooq.impl.SelectQueryImpl.toSQLReference0(SelectQueryImpl.java:2349)
    at org.jooq.impl.SelectQueryImpl.lambda$toSQLReferenceLimitDefault$21(SelectQueryImpl.java:1865)
    at org.jooq.impl.AbstractContext.toggle(AbstractContext.java:333)
    at org.jooq.impl.AbstractContext.data(AbstractContext.java:344)
    at org.jooq.impl.SelectQueryImpl.toSQLReferenceLimitDefault(SelectQueryImpl.java:1865)
    at org.jooq.impl.SelectQueryImpl.accept0(SelectQueryImpl.java:1779)
    at org.jooq.impl.SelectQueryImpl.accept(SelectQueryImpl.java:1435)
    at org.jooq.impl.DefaultRenderContext.visit0(DefaultRenderContext.java:720)
    at org.jooq.impl.AbstractContext.visit(AbstractContext.java:296)
    at org.jooq.impl.DefaultDSLContext.render(DefaultDSLContext.java:709)
    at org.jooq.impl.Tools.hash(Tools.java:3256)
    at org.jooq.impl.Tools.autoAlias(Tools.java:3233)
    at org.jooq.impl.SelectQueryImpl.asTable(SelectQueryImpl.java:668)
    at org.jooq.impl.SelectQueryImpl.fieldsRow(SelectQueryImpl.java:661)
    at org.jooq.impl.FieldsTrait.fields(FieldsTrait.java:57)
    at org.jooq.impl.Tools.dataTypes(Tools.java:3439)
    at org.jooq.impl.Tools.scalarType(Tools.java:3443)
    at org.jooq.impl.SelectQueryImpl.asField(SelectQueryImpl.java:646)
    at org.jooq.impl.SelectImpl.asField(SelectImpl.java:2921)
    at org.jooq.impl.UpdateImpl.set(UpdateImpl.java:154)
    at org.jooq.impl.UpdateImpl.set(UpdateImpl.java:122)
    at com.mycompany.api.service.impl.CreateInvoiceRecordsHelperServiceImpl.postInvoices(CreateInvoiceRecordsHelperServiceImpl.java:61)
    at com.mycompany.api.service.impl.CreateInvoiceRecordsHelperServiceImpl.createInvoiceRecords(CreateInvoiceRecordsHelperServiceImpl.java:54)
    at com.mycompany.api.service.impl.CreateInvoiceRecordsHelperServiceImpl$$FastClassBySpringCGLIB$$73261fc1.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708)
    at com.mycompany.api.service.impl.CreateInvoiceRecordsHelperServiceImpl$$EnhancerBySpringCGLIB$$378b940a.createInvoiceRecords(<generated>)
    at com.mycompany.api.service.impl.ArInvoiceServiceImpl.createInvoiceRecords(ArInvoiceServiceImpl.java:137)
    at com.mycompany.api.service.impl.ArInvoiceServiceImplIT.testCreateInvoiceRecords(ArInvoiceServiceImplIT.java:185)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)
    at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
    at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
    at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:214)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:210)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:66)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
    at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
    at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
    at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: java.sql.SQLFeatureNotSupportedException
    at com.mycompany.jooq.binding.AbstractSmallintEnumBinding.sql(AbstractSmallintEnumBinding.java:42)
    at com.mycompany.jooq.binding.BillingStatusBinding.sql(BillingStatusBinding.java:7)
    at org.jooq.impl.Val.accept(Val.java:182)
    ... 122 more

推荐答案

正如我所怀疑的那样,正如您在堆栈跟踪中看到的那样,对使用SQLDialect.DEFAULT的绑定的意外调用来自一些不一定特定于方言的内部代码,即:

    at org.jooq.impl.DefaultDSLContext.render(DefaultDSLContext.java:709)
    at org.jooq.impl.Tools.hash(Tools.java:3256)
    at org.jooq.impl.Tools.autoAlias(Tools.java:3233)
    at org.jooq.impl.SelectQueryImpl.asTable(SelectQueryImpl.java:668)

正在为子查询生成别名,以便访问其字段(就像它是派生表一样).这实际上对您的INFORMIX个特定的SQL没有那么大的影响.现在,这个散列操作忽略SQLDialect可能是错误,也可能不是错误,我还不确定(如果此行为在最新版本的jOOQ中仍然存在,您可以报告一个问题).

请注意,在jOOQ 3.17中,实现了一项改进,以帮助避免在不是严格必要的情况下(例如,在您的情况下)调用TableLike::asTable可能很慢的情况:

无论如何,你的Binding不应该在SQLDialect.DEFAULT上抛出一个例外.SQLDialect没有设置为您配置的方言可能还有其他原因,例如,在记录事件时,或者在无法访问您的Configuration的情况下呈现SQL的任何其他情况.

我们还有其他从Spring Boot2.x迁移到3.x的拦截器,我们可以使用更新的jOOQ版本.

我不确定Spring Boot2.x是否真的会阻止您升级到更新版本的jOOQ.Spring Boot与jOOQ的交互非常肤浅(为您创建了Configuration),而且jOOQ是向后兼容的,所以我怀疑Spring Boot是否会注意到您对jOOQ的升级.

Java相关问答推荐

将偶数元素移动到数组的前面,同时保持相对顺序

具有默认分支的JUnit代码覆盖率切换声明

将具有多个未知字段的SON映射到Java POJO

使用包私有构造函数强制子类Java类

Cucumber TestNG Assert失败,出现java. lang. Numbercycle异常

方法没有用正确的值填充数组—而是将数组保留为null,'

如果一个子类没有构造函数,超类也没有构造函数,那么为什么我可以构造子类的实例呢?

如何调用Firebase Realtime Database中的子图像列表到android studio中的回收器视图?

所有 case 一起输入时输出错误,而单独放置时输出正确

具有多种令牌类型和段的复杂Java 17正则表达式

是否在允许数组元素为空时阻止 idea 为空性警告?

无法了解Java线程所消耗的时间

Com.google.firebase.database.DatabaseException:无法将类型为java.lang.Boolean的值转换为字符串.这是关于什么的?

使用存储在字符串变量中的路径目录打开.pdf文件

S数学.exp的相同错误保证也适用于StrictMath.exp吗?

为了安全起见,有必要复制一份 list 吗?

没有Tomcat,IntelliJ如何在本地运行API?

按长度排序字符串数组

从 Java 17 切换回 Java 8 后出现的问题

找不到 jar 文件系统提供程序try 使用 jdeps 和 jlink 创建收缩 Java 映像来运行 Minecraft