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