gpt4 book ai didi

java - spring data jpa stackoverflow错误

转载 作者:行者123 更新时间:2023-12-01 08:52:32 32 4
gpt4 key购买 nike

我有一个简单的获取请求来获取基于topicId的信息,该信息存储在数据库中为1486485753923

@RequestMapping(path = "/get_topic_details", method = RequestMethod.GET)
public ResponseEntity get_topic_details(@RequestParam(value="topicId") long topicId) throws Exception {
System.out.println("Topic id is " + topicId);
TopicBean topicBean = topicService.findByTopicId(topicId);
return new ResponseEntity(topicBean, HttpStatus.OK);
}

存储库:

@Repository
public interface TopicRepository extends JpaRepository<TopicBean, Long>{

List<TopicBean> findTop10ByUsername(String username);

Page<TopicBean> findAllByPage(Pageable pageable);

// @Query("SELECT t FROM TopicBean t WHERE (t.topicId) = (:topicId)")
TopicBean findByTopicId(long topicId);

@Transactional
Long deleteByTopicId(String topicId);

List<TopicBean> findByUsername(String username);
}

我收到此错误:

2017-02-17 13:44:50.542 DEBUG 4828 --- [nio-8080-exec-1] .m.m.a.ExceptionHandlerExceptionResolver : Resolving exception from handler [public org.springframework.http.ResponseEntity seconds47.restAPI.TopicsRest.get_topic_details(long) throws java.lang.Exception]: org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.StackOverflowError

org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.StackOverflowError
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:978) ~[spring-webmvc-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) [spring-webmvc-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) [spring-webmvc-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-embed-websocket-8.5.6.jar:8.5.6]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) [spring-web-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:89) [spring-web-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) [spring-web-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) [spring-web-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410) [tomcat-embed-core-8.5.6.jar:8.5.6]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.6.jar:8.5.6]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_102]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_102]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.6.jar:8.5.6]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_102]

打印调试信息:

2017-02-17 13:44:51.132 DEBUG 4828 --- [nio-8080-exec-1] o.s.w.s.DispatcherServlet                : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/error]
2017-02-17 13:44:51.132 DEBUG 4828 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /error
2017-02-17 13:44:51.134 DEBUG 4828 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)]
2017-02-17 13:44:51.134 DEBUG 4828 --- [nio-8080-exec-1] o.s.w.s.DispatcherServlet : Last-Modified value for [/error] is: -1
2017-02-17 13:44:51.270 DEBUG 4828 --- [nio-8080-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Written [{timestamp=Fri Feb 17 13:44:51 IST 2017, status=500, error=Internal Server Error, exception=java.lang.StackOverflowError, message=No message available, path=/get_topic_details}] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@2e3900dc]
2017-02-17 13:44:51.272 DEBUG 4828 --- [nio-8080-exec-1] o.s.w.s.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2017-02-17 13:44:51.272 DEBUG 4828 --- [nio-8080-exec-1] o.s.w.s.DispatcherServlet : Successfully completed request
2017-02-17 13:44:51.306 DEBUG 4828 --- [nio-8080-exec-2] o.s.w.s.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/get_comments_by_topicId]
2017-02-17 13:44:51.307 DEBUG 4828 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /get_comments_by_topicId
2017-02-17 13:44:51.308 DEBUG 4828 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public java.util.List<seconds47.beans.CommentBean> seconds47.restAPI.CommentRest.getCommentsByTopicId(java.lang.String)]
2017-02-17 13:44:51.308 DEBUG 4828 --- [nio-8080-exec-2] o.s.w.s.DispatcherServlet : Last-Modified value for [/get_comments_by_topicId] is: -1
2017-02-17 13:44:51.325 DEBUG 4828 --- [nio-8080-exec-2] o.h.j.c.CriteriaQueryImpl : Rendered criteria query -> select generatedAlias0 from CommentBean as generatedAlias0 where generatedAlias0.topicId=:param0
2017-02-17 13:44:51.347 DEBUG 4828 --- [nio-8080-exec-2] o.h.h.i.QueryTranslatorFactoryInitiator : QueryTranslatorFactory : org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory@22d0cb47
2017-02-17 13:44:51.347 INFO 4828 --- [nio-8080-exec-2] o.h.h.i.QueryTranslatorFactoryInitiator : HHH000397: Using ASTQueryTranslatorFactory
2017-02-17 13:44:51.422 DEBUG 4828 --- [nio-8080-exec-2] o.h.h.i.a.QueryTranslatorImpl : parse() - HQL: select generatedAlias0 from seconds47.beans.CommentBean as generatedAlias0 where generatedAlias0.topicId=:param0
2017-02-17 13:44:51.444 DEBUG 4828 --- [nio-8080-exec-2] o.h.h.i.a.QueryTranslatorImpl : --- HQL AST ---
\-[QUERY] Node: 'query'
+-[SELECT_FROM] Node: 'SELECT_FROM'
| +-[FROM] Node: 'from'
| | \-[RANGE] Node: 'RANGE'
| | +-[DOT] Node: '.'
| | | +-[DOT] Node: '.'
| | | | +-[IDENT] Node: 'seconds47'
| | | | \-[IDENT] Node: 'beans'
| | | \-[IDENT] Node: 'CommentBean'
| | \-[ALIAS] Node: 'generatedAlias0'
| \-[SELECT] Node: 'select'
| \-[IDENT] Node: 'generatedAlias0'
\-[WHERE] Node: 'where'
\-[EQ] Node: '='
+-[DOT] Node: '.'
| +-[IDENT] Node: 'generatedAlias0'
| \-[IDENT] Node: 'topicId'
\-[COLON] Node: ':'
\-[IDENT] Node: 'param0'

2017-02-17 13:44:51.444 DEBUG 4828 --- [nio-8080-exec-2] o.h.h.i.a.ErrorCounter : throwQueryException() : no errors
2017-02-17 13:44:51.508 DEBUG 4828 --- [nio-8080-exec-2] o.h.h.i.a.HqlSqlBaseWalker : select << begin [level=1, statement=select]
2017-02-17 13:44:51.540 DEBUG 4828 --- [nio-8080-exec-2] o.h.h.i.a.t.FromElement : FromClause{level=1} : seconds47.beans.CommentBean (generatedAlias0) -> commentbea0_
2017-02-17 13:44:51.542 DEBUG 4828 --- [nio-8080-exec-2] o.h.h.i.a.t.FromReferenceNode : Resolved : generatedAlias0 -> commentbea0_.id
2017-02-17 13:44:51.550 DEBUG 4828 --- [nio-8080-exec-2] o.h.h.i.a.t.FromReferenceNode : Resolved : generatedAlias0 -> commentbea0_.id
2017-02-17 13:44:51.552 DEBUG 4828 --- [nio-8080-exec-2] o.h.h.i.a.t.DotNode : getDataType() : topicId -> org.hibernate.type.StringType@3af10d0b
2017-02-17 13:44:51.553 DEBUG 4828 --- [nio-8080-exec-2] o.h.h.i.a.t.FromReferenceNode : Resolved : generatedAlias0.topicId -> commentbea0_.topicId
2017-02-17 13:44:51.557 DEBUG 4828 --- [nio-8080-exec-2] o.h.h.i.a.HqlSqlBaseWalker : select : finishing up [level=1, statement=select]
2017-02-17 13:44:51.557 DEBUG 4828 --- [nio-8080-exec-2] o.h.h.i.a.HqlSqlWalker : processQuery() : ( SELECT ( {select clause} commentbea0_.id ) ( FromClause{level=1} comments commentbea0_ ) ( where ( = ( commentbea0_.topicId commentbea0_.id topicId ) ? ) ) )
2017-02-17 13:44:51.572 DEBUG 4828 --- [nio-8080-exec-2] o.h.h.i.a.u.JoinProcessor : Using FROM fragment [comments commentbea0_]
2017-02-17 13:44:51.572 DEBUG 4828 --- [nio-8080-exec-2] o.h.h.i.a.HqlSqlBaseWalker : select >> end [level=1, statement=select]
2017-02-17 13:44:51.573 DEBUG 4828 --- [nio-8080-exec-2] o.h.h.i.a.QueryTranslatorImpl : --- SQL AST ---
\-[SELECT] QueryNode: 'SELECT' querySpaces (comments)
+-[SELECT_CLAUSE] SelectClause: '{select clause}'
| +-[ALIAS_REF] IdentNode: 'commentbea0_.id as id1_2_' {alias=generatedAlias0, className=seconds47.beans.CommentBean, tableAlias=commentbea0_}
| \-[SQL_TOKEN] SqlFragment: 'commentbea0_.commentDate as commentD2_2_, commentbea0_.commentId as commentI3_2_, commentbea0_.comments as comments4_2_, commentbea0_.topicId as topicId5_2_, commentbea0_.userImage as userImag6_2_, commentbea0_.username as username7_2_'
+-[FROM] FromClause: 'from' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=[generatedAlias0], fromElementByTableAlias=[commentbea0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]}
| \-[FROM_FRAGMENT] FromElement: 'comments commentbea0_' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=generatedAlias0,role=null,tableName=comments,tableAlias=commentbea0_,origin=null,columns={,className=seconds47.beans.CommentBean}}
\-[WHERE] SqlNode: 'where'
\-[EQ] BinaryLogicOperatorNode: '='
+-[DOT] DotNode: 'commentbea0_.topicId' {propertyName=topicId,dereferenceType=PRIMITIVE,getPropertyPath=topicId,path=generatedAlias0.topicId,tableAlias=commentbea0_,className=seconds47.beans.CommentBean,classAlias=generatedAlias0}
| +-[ALIAS_REF] IdentNode: 'commentbea0_.id' {alias=generatedAlias0, className=seconds47.beans.CommentBean, tableAlias=commentbea0_}
| \-[IDENT] IdentNode: 'topicId' {originalText=topicId}
\-[NAMED_PARAM] ParameterNode: '?' {name=param0, expectedType=org.hibernate.type.StringType@3af10d0b}

2017-02-17 13:44:51.573 DEBUG 4828 --- [nio-8080-exec-2] o.h.h.i.a.ErrorCounter : throwQueryException() : no errors
2017-02-17 13:44:51.585 DEBUG 4828 --- [nio-8080-exec-2] o.h.h.i.a.QueryTranslatorImpl : HQL: select generatedAlias0 from seconds47.beans.CommentBean as generatedAlias0 where generatedAlias0.topicId=:param0
2017-02-17 13:44:51.586 DEBUG 4828 --- [nio-8080-exec-2] o.h.h.i.a.QueryTranslatorImpl : SQL: select commentbea0_.id as id1_2_, commentbea0_.commentDate as commentD2_2_, commentbea0_.commentId as commentI3_2_, commentbea0_.comments as comments4_2_, commentbea0_.topicId as topicId5_2_, commentbea0_.userImage as userImag6_2_, commentbea0_.username as username7_2_ from comments commentbea0_ where commentbea0_.topicId=?
2017-02-17 13:44:51.586 DEBUG 4828 --- [nio-8080-exec-2] o.h.h.i.a.ErrorCounter : throwQueryException() : no errors
2017-02-17 13:44:51.645 DEBUG 4828 --- [nio-8080-exec-2] o.h.SQL : select commentbea0_.id as id1_2_, commentbea0_.commentDate as commentD2_2_, commentbea0_.commentId as commentI3_2_, commentbea0_.comments as comments4_2_, commentbea0_.topicId as topicId5_2_, commentbea0_.userImage as userImag6_2_, commentbea0_.username as username7_2_ from comments commentbea0_ where commentbea0_.topicId=?
2017-02-17 13:44:51.702 DEBUG 4828 --- [nio-8080-exec-2] m.m.a.RequestResponseBodyMethodProcessor : Written [[]] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@2e3900dc]
2017-02-17 13:44:51.702 DEBUG 4828 --- [nio-8080-exec-2] o.s.w.s.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2017-02-17 13:44:51.702 DEBUG 4828 --- [nio-8080-exec-2] o.s.w.s.DispatcherServlet : Successfully completed request

我不明白这里有什么问题。

请任何机构帮忙。过去两天我一直在努力解决这个问题。

最佳答案

我还不能发表评论,所以我会写在这里。问题可能出在您的 ResponseEntity 中。请也发布该类的代码。 Stackoverflow 让我想到了递归和自引用方法。任何地方都会发生类似的事情吗?

关于java - spring data jpa stackoverflow错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42292845/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com