Blazebit / blaze-persistence

Rich Criteria API for JPA providers
https://persistence.blazebit.com
Apache License 2.0
727 stars 85 forks source link

QueryDSL and EntitiView error in the object constructor #1644

Open MaykoST opened 1 year ago

MaykoST commented 1 year ago

I'm trying to use the QueryDSL integration with EntityViews as suggested here https://github.com/Blazebit/blaze-persistence/issues/1643, but i found a problem in the object construction code.

Code: image

Map: image

Error: image

As can be seen in the image the wrong positions are used to access the object in the array.

My dependencies

querydsl:4.1.4 spring-boot:2.0.0 spring:5.0.4 laze-persistence: 1.6.8

java8

jwgmeligmeyling commented 1 year ago

I think if you use evm.applySetting you should remove any select statement from your query.

MaykoST commented 1 year ago

I tried it before, but i got another error

image

stackTrace: java.lang.NullPointerException at com.blazebit.persistence.querydsl.BlazeCriteriaBuilderRenderer$CTERenderVisitor.visit(BlazeCriteriaBuilderRenderer.java:1526) at com.querydsl.core.types.SubQueryExpressionImpl.accept(SubQueryExpressionImpl.java:57) at com.querydsl.core.support.FetchableSubQueryBase.accept(FetchableSubQueryBase.java:150) at com.blazebit.persistence.querydsl.BlazeCriteriaBuilderRenderer.renderCTEs(BlazeCriteriaBuilderRenderer.java:367) at com.blazebit.persistence.querydsl.BlazeCriteriaBuilderRenderer.render(BlazeCriteriaBuilderRenderer.java:130) at com.betha.pessoal.folha.integracao.esocial.application.ESocialResource.buscaConfiguracao(ESocialResource.java:158) at com.betha.pessoal.folha.integracao.esocial.application.ESocialResource$$FastClassBySpringCGLIB$$8ca41cf5.invoke() at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:747) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689) at com.betha.pessoal.folha.integracao.esocial.application.ESocialResource$$EnhancerBySpringCGLIB$$d25b058b.buscaConfiguracao() at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:870) at javax.servlet.http.HttpServlet.service(HttpServlet.java:635) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855) at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:158) at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:126) at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:111) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:84) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:750)

beikov commented 1 year ago

Yeah, I think the NPE there is wrong. We should fix it.

jwgmeligmeyling commented 1 year ago

Are you sure you have shared the full query with us however? This method is for rendering CTE's and not simple queries like the one demonstrated in the issue.

MaykoST commented 1 year ago

Yes i did, I added the screenshot of the code. I also found it strange that the error happened in the cte-related part, but that was exactly the code I ran. The NPE happens if i remove the select part.

NorbertKominak commented 1 year ago

Hi. I am facing the same issue. Could you provide a deeper explanation on the NPE problem? Is there any workaround to get working the queryDSL integration with Entity Views at the moment, please?

beikov commented 1 year ago

It would be very helpful if you could provide us a reproducer for this issue. Maybe try using the archetype for this purpose: mvn archetype:generate "-DarchetypeGroupId=com.blazebit" "-DarchetypeArtifactId=blaze-persistence-archetype-entity-view-sample" "-DarchetypeVersion=1.6.8"

NorbertKominak commented 1 year ago

Thanks for a really quick reply! Please find the reproducer here https://github.com/NorbertKominak/BlazePersistenceEntityViewError. It is a simple Spring Boot app.

NorbertKominak commented 1 year ago

Thanks for a really quick reply! Please find the reproducer here https://github.com/NorbertKominak/BlazePersistenceEntityViewError. It is a simple Spring Boot app.

@beikov could you confirm if you can run the reproducer and see the error, please?

beikov commented 1 year ago

Thanks for the reproducer. I didn't try it myself, but since @jwgmeligmeyling will be working on this, I'm sure he has :)

NorbertKominak commented 1 year ago

@jwgmeligmeyling Is there any workaround at the moment on how to avoid the NPE and use queryDSL with the Entity View module, please?

jwgmeligmeyling commented 1 year ago

I don't think there is an easy workaround although it should be relatively easy to fix.

Basically add a null-check on the result of queryMetadata.getProjection() here and here.

I am currently working on Hibernate 6 support for Querydsl, Querydsl Hibernate Types and Querydsl Blaze-Persistence integrations, so I can't pick this up right now but I'll try to squeeze it in before the next Blaze-Persistence release.

NorbertKominak commented 1 year ago

I don't think there is an easy workaround although it should be relatively easy to fix.

Basically add a null-check on the result of queryMetadata.getProjection() here and here.

I am currently working on Hibernate 6 support for Querydsl, Querydsl Hibernate Types and Querydsl Blaze-Persistence integrations, so I can't pick this up right now but I'll try to squeeze it in before the next Blaze-Persistence release.

Thanks! When is the next released planned, please?

beikov commented 1 year ago

The next release is dependent on Spring Boot 3 and Hibernate 6.2 support, and it currently looks like this will take at least 2 more weeks.