5

How to resolve "could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement"?

I have got such this error while running my app. I share my code snippet related service and repository. When I change the reportStatus of comment and post, I get contrasted results of success and failure.

The configured yaml file is below.

 jpa:
    open-in-view: false
    database: MYSQL
    generate-ddl: true
    show-sql: true
    hibernate:
      ddl-auto: update
      naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy

    properties:
      hibernate:
        use-new-id-generator-mappings: false
        enable_lazy_load_no_trans: true
        format_sql: true
        use_sql_comments: true
        dialect: org.hibernate.dialect.MySQL5InnoDBDialect
#       dialect: org.hibernate.spatial.dialect.mysql.MySQL5SpatialDialect
        default_batch_fetch_size: 100
        search:
          autoregister_listeners: false
          indexing_strategy: manual
          default:
            indexmanager: elasticsearch   #5.6.16
          elasticsearch:
            host: http://localhost:9200
              index_schema_management_strategy: update   #update
              #username: user
              #password: password
              log:
                json_pretty_printing: true
              required_index_status: yellow
              dynamic_mapping: true
              update_all_types: true
// RestAdminReportController //

    @JsonView(Views.WebAdminJsonView.class)
  @PostMapping(path = "/{id}/changeStatus")
  public ResponseEntity<Map<String, Object>> changeStatus(@PathVariable long id, @RequestParam ReportStatus reportStatus, @RequestParam long reportId) {
    Map<String, Object> map = new HashMap<>();

    User loginUser = authUtils.getCurrentUser();
    log.info("ReportID : {}, PostingID : {}, ChangeStatus : {}", reportId, id, reportStatus);
    ReportPosting report = adminReportPostingService.findById(reportId);
    adminReportPostingService.updateAll(report.getRelation().getPosting(), reportStatus);
    boolean isBlind = reportStatus.equals(ReportStatus.BLOCK);
    postingService.blindPosting(id, loginUser, isBlind);

    map.put("resultCode", "1000");
    map.put("data", "");
    return new ResponseEntity<>(map, HttpStatus.OK);
  }

  @JsonView(Views.WebAdminJsonView.class)
  @PostMapping(path = "/{id}/changeCommentStatus")
  public ResponseEntity<Map<String, Object>> changeCommentStatus(@PathVariable long id, @RequestParam ReportStatus reportStatus, @RequestParam long reportId) {
    Map<String, Object> map = new HashMap<>();

    User loginUser = authUtils.getCurrentUser();
    log.info("ReportID : {}, CommentID : {}, ChangeStatus : {}", reportId, id, reportStatus);
    ReportComment report = adminReportCommentService.findById(reportId);
    adminReportCommentService.updateAll(report.getRelation().getComment(), reportStatus);


    boolean isBlind = reportStatus.equals(ReportStatus.BLOCK);
    postingService.blindComment(id, loginUser, isBlind);

    map.put("resultCode", "1000");
    map.put("data", "");
    return new ResponseEntity<>(map, HttpStatus.OK);
  }

// ReportCommentRepository //
public interface ReportCommentRepository extends JpaRepository<ReportComment, Long> {
    ...

    @Modifying
    @Query("update ReportComment rc set rc.reportStatus = :status where rc.relation.comment.id = :#{#comment.id}")
    int updateAll(@Param("comment")Comment comment, @Param("status") ReportStatus status);
}

// ReportPostingRepository //

public interface ReportPostingRepository extends JpaRepository<ReportPosting, Long> {

    ...

    @Modifying
    @Query("update ReportPosting rc set rc.reportStatus = :status where rc.relation.posting.id = :#{#posting.id}")
    int updateAll(@Param("posting") Posting posting, @Param("status") ReportStatus status);
}

// Posting Model //

@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@DiscriminatorColumn(columnDefinition = "char(2)", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("PO")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@NoArgsConstructor
@AllArgsConstructor
@ToString()
@Where(clause = "is_delete = false")
@DynamicUpdate
@AnalyzerDef(name = "text_analyzer",
        tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
        filters = {
                @TokenFilterDef(factory = StandardFilterFactory.class),
                @TokenFilterDef(factory = LowerCaseFilterFactory.class),
                @TokenFilterDef(factory = StopFilterFactory.class),
        }
)
@Table(indexes = {@Index(name = "IDX_TYPE", columnList = "dtype")})
public abstract class Posting extends BaseEntity implements INotification, WithCondition, IActivity, IYoutube, IPhotoAlbum {
  ...
}

// Comment Model //

@Data
//@Indexed(index = ElasticsearchConfig.INDEX_NAME)
@Entity
@DynamicUpdate
@NoArgsConstructor
@AllArgsConstructor
@Builder
@EqualsAndHashCode(callSuper = false, of = {"id"})
@ToString
@Table(indexes = {@javax.persistence.Index(name = "IDX_POSTING", columnList = "posting_id")})
@JsonIgnoreProperties({"hibernateLazwyInitializer"})
@AnalyzerDef(name = "comment",
        tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
        filters = {
                @TokenFilterDef(factory = StandardFilterFactory.class),
                @TokenFilterDef(factory = LowerCaseFilterFactory.class),
                @TokenFilterDef(factory = StopFilterFactory.class),
        }
)
@AnalyzerDef(name = "comment_remove_nickname_analyzer", charFilters =
        {
                @CharFilterDef(factory = PatternReplaceCharFilterFactory.class, params =
                        {
                                @Parameter(name = "pattern", value = "(\\[.*\\])"),
                                @Parameter(name = "replacement", value = "")
                        })
        }, tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class), filters =
        {
                @TokenFilterDef(factory = StandardFilterFactory.class), @TokenFilterDef(factory = LowerCaseFilterFactory.class),
        })

public class Comment extends BaseEntity implements INotification, IActivity {
  ...
}

After run the below function, I got the comment item updated successfully.

adminReportCommentService.updateAll(report.getRelation().getComment(), reportStatus);

On the contrary, there is another function but similar in logic. And after this function run, got a failure like below.

adminReportPostingService.updateAll(report.getRelation().getPosting(), reportStatus);
[Admin][2022-08-10 00:55:22][TRACE][BasicBinder.java][bind(64)] : binding parameter [1] as [INTEGER] - [2]
[Admin][2022-08-10 00:55:22][TRACE][BasicBinder.java][bind(64)] : binding parameter [2] as [BIGINT] - [2003441]
[Admin][2022-08-10 00:55:22][WARN ][SqlExceptionHelper.java][logExceptions(137)] : SQL Error: 1064, SQLState: 42000
[Admin][2022-08-10 00:55:22][ERROR][SqlExceptionHelper.java][logExceptions(142)] : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'set report_status=2 where id=2003441' at line 1
[Admin][2022-08-10 00:55:22][INFO ][ProxyLeakTask.java][cancel(91)] : Previously reported leaked connection com.mysql.cj.jdbc.ConnectionImpl@20d18bbc on thread http-nio-8081-exec-6 was returned to the pool (unleaked)
[Admin][2022-08-10 00:55:22][ERROR][CommonExceptionHandler.java][paramViolationError(99)] : paramViolationError
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement
        at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:259)
        at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:233)
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:551)
        at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
        at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:152)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:145)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
        at jdk.proxy2/jdk.proxy2.$Proxy233.updateAll(Unknown Source)
        at net.infobank.moyamo.service.AdminReportPostingService.updateAll(AdminReportPostingService.java:44)
        at net.infobank.moyamo.service.AdminReportPostingService$$FastClassBySpringCGLIB$$636acc8e.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:779)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
        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:750)
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692)
        at net.infobank.moyamo.service.AdminReportPostingService$$EnhancerBySpringCGLIB$$d8cddc1f.updateAll(<generated>)
        at net.infobank.moyamo.controller.RestAdminReportController.changeStatus(RestAdminReportController.java:85)
        at net.infobank.moyamo.controller.RestAdminReportController$$FastClassBySpringCGLIB$$b2100f08.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:779)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
        at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89)
        at net.infobank.moyamo.aop.AdminRestAspect.restApiControllerAdviceAround(AdminRestAspect.java:36)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:577)
        at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:634)
        at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:624)
        at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:72)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692)
        at net.infobank.moyamo.controller.RestAdminReportController$$EnhancerBySpringCGLIB$$593eb73f.changeStatus(<generated>)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:577)
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:197)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:141)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:894)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1063)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:517)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:584)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:327)
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:115)
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:81)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
        at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119)
        at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
        at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:126)
        at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:81)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
        at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:105)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
        at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:149)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
        at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
        at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:218)
        at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:212)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
        at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:218)
        at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:212)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
        at org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestRedirectFilter.doFilterInternal(OAuth2AuthorizationRequestRedirectFilter.java:178)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
        at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:103)
        at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:89)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
        at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:90)
        at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:75)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
        at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:110)
        at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:80)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
        at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:55)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
        at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:211)
        at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:183)
        at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358)
        at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
        at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
        at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:97)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1707)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement
        at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:200)
        at org.hibernate.hql.internal.ast.exec.BasicExecutor.doExecute(BasicExecutor.java:80)
        at org.hibernate.hql.internal.ast.exec.BasicExecutor.execute(BasicExecutor.java:50)
        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:458)
        at org.hibernate.engine.query.spi.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:377)
        at org.hibernate.internal.SessionImpl.executeUpdate(SessionImpl.java:1438)
        at org.hibernate.query.internal.AbstractProducedQuery.doExecuteUpdate(AbstractProducedQuery.java:1701)
        at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1683)
        at org.springframework.data.jpa.repository.query.JpaQueryExecution$ModifyingExecution.doExecute(JpaQueryExecution.java:239)
        at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:88)
        at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:155)
        at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:143)
        at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:137)
        at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:121)
        at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:152)
        at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:131)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        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.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137)
        ... 133 common frames omitted
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'set report_status=2 where id=2003441' at line 1
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
        at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
        at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1092)
        at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1040)
        at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1347)
        at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:1025)
        at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
        at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:197)
        ... 156 common frames omitted

There are several types of models extended Posting model, such as Boast, Clinic, Free, Guide, Magazine, etc.

I thought this errors turn on because Posting model is abstract class whereas Comment model is not abstract class. Am I right?

I need your help.

2
  • maybe get rid of rc Commented Aug 10, 2022 at 5:22
  • can you write completed answer or example?
    – MXX
    Commented Aug 10, 2022 at 5:26

3 Answers 3

2

I added updateReportStatus function, since the "updateAll" function changes updates only report status.

    @Transactional
    public int updateAll(Posting posting, ReportStatus status) {
        return reportPostingRepository.updateAll(posting, status);
    }

    @Transactional
    public int updateReportStatus(ReportPosting report, ReportStatus status) {
        return reportPostingRepository.updateReportStatus(report, status);
    }
    @Modifying
    @Query("update ReportPosting rp set rp.reportStatus = :status where rp.id = :#{#report.id}")
    int updateReportStatus(@Param("report") ReportPosting report, @Param("status") ReportStatus status);
        ReportPosting report = adminReportPostingService.findById(reportId);
//      adminReportPostingService.updateAll(report.getRelation().getPosting(), reportStatus); // By this line, getting error.
        adminReportPostingService.updateReportStatus(report, reportStatus);

Finally, I could get reportPosting item updated by reportStatus.

1

You need not to use alias for the table.

public interface ReportCommentRepository extends JpaRepository<ReportComment, Long> {
    @Modifying
    @Query("update ReportComment  set reportStatus = :status where relation.comment.id = :#{#comment.id}")
    int updateAll(@Param("comment")Comment comment, @Param("status") ReportStatus status); }
6
  • still got the same error.
    – MXX
    Commented Aug 10, 2022 at 5:51
  • log.info("ReportID : {}, PostingID : {}, ChangeStatus : {}", reportId, id, reportStatus); After this command, I can see the log info. But after this command below ReportComment report = adminReportCommentService.findById(reportId); I can't get the report object and can't see the log below. log.info("REACHED 1st -> report : {}, comment : {}, status : {}", report.getId(), report.getRelation().getComment(), reportStatus);
    – MXX
    Commented Aug 10, 2022 at 6:01
  • can you check this issue again? I updated post.
    – MXX
    Commented Aug 10, 2022 at 13:43
  • I guess, it might be because of ReportStatus. How did you bind the ReportStatus enum in the entity, as Ordinal or String. It seems like Ordinal, please send the param as number in the query if it's ordinal Commented Aug 17, 2022 at 6:24
  • Exactly, the reportStatus is EnumType.ORDINAL. public enum ReportStatus { WAIT, HOLD, BLOCK } @Accessors(chain = true) @NonNull @Column(columnDefinition = "tinyint default 0") @Enumerated(EnumType.ORDINAL) @JsonView(Views.WebAdminJsonView.class) private ReportStatus reportStatus;
    – MXX
    Commented Aug 18, 2022 at 9:04
0

For me to solve this problem. I found that I did not create a default constructor of Entity POJO class. I solved it by creating default constructor(NoArgsConstructor).

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Nov 13, 2022 at 12:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.