Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Can only solve the failed to lazily initialize a collection of role problem in Java

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "can only solve the failed to lazily initialize a collection of role problem in Java". In the daily operation, I believe many people have doubts in solving the failed to lazily initialize a collection of role problem in Java. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubt that "you can only solve the failed to lazily initialize a collection of role problem in Java"! Next, please follow the editor to study!

Net.sf.json.JSONException: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.gwl.bos.model.Region.subareas, could not initialize proxy-no Session

At net.sf.json.JSONObject.defaultBeanProcessing (JSONObject.java:818)

At net.sf.json.JSONObject._fromBean (JSONObject.java:699)

At net.sf.json.JSONObject.fromObject (JSONObject.java:172)

At net.sf.json.AbstractJSON._processValue (AbstractJSON.java:274)

At net.sf.json.JSONArray._processValue (JSONArray.java:2513)

At net.sf.json.JSONArray.processValue (JSONArray.java:2538)

At net.sf.json.JSONArray.addValue (JSONArray.java:2525)

At net.sf.json.JSONArray._fromCollection (JSONArray.java:1056)

At net.sf.json.JSONArray.fromObject (JSONArray.java:123)

At com.gwl.bos.web.action.base.BaseAction.responseJson (BaseAction.java:72)

At com.gwl.bos.web.action.RegionAction.listJson (RegionAction.java:112)

At java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (NativeMethod)

At java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)

At java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)

At java.base/java.lang.reflect.Method.invoke (Method.java:566)

At ognl.OgnlRuntime.invokeMethod (OgnlRuntime.java:902)

At ognl.OgnlRuntime.callAppropriateMethod (OgnlRuntime.java:1547)

At ognl.ObjectMethodAccessor.callMethod (ObjectMethodAccessor.java:68)

At com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo (XWorkMethodAccessor.java:98)

At com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod (XWorkMethodAccessor.java:90)

At ognl.OgnlRuntime.callMethod (OgnlRuntime.java:1623)

At ognl.ASTMethod.getValueBody (ASTMethod.java:91)

At ognl.SimpleNode.evaluateGetValueBody (SimpleNode.java:212)

At ognl.SimpleNode.getValue (SimpleNode.java:258)

At ognl.Ognl.getValue (Ognl.java:470)

At ognl.Ognl.getValue (Ognl.java:434)

At com.opensymphony.xwork2.ognl.OgnlUtil$3.execute (OgnlUtil.java:401)

At com.opensymphony.xwork2.ognl.OgnlUtil.compileAndExecuteMethod (OgnlUtil.java:453)

At com.opensymphony.xwork2.ognl.OgnlUtil.callMethod (OgnlUtil.java:399)

At com.opensymphony.xwork2.DefaultActionInvocation.invokeAction (DefaultActionInvocation.java:438)

At com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly (DefaultActionInvocation.java:293)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:254)

At org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept (DebuggingInterceptor.java:250)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:249)

At com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept (DefaultWorkflowInterceptor.java:179)

At com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept (MethodFilterInterceptor.java:99)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:249)

At com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept (ValidationInterceptor.java:263)

At org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept (AnnotationValidationInterceptor.java:49)

At com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept (MethodFilterInterceptor.java:99)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:249)

At com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.doIntercept (ConversionErrorInterceptor.java:142)

At com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept (MethodFilterInterceptor.java:99)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:249)

At com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept (ParametersInterceptor.java:137)

At com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept (MethodFilterInterceptor.java:99)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:249)

At com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept (ParametersInterceptor.java:137)

At com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept (MethodFilterInterceptor.java:99)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:249)

At com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept (StaticParametersInterceptor.java:201)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:249)

At org.apache.struts2.interceptor.MultiselectInterceptor.intercept (MultiselectInterceptor.java:67)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:249)

At org.apache.struts2.interceptor.DateTextFieldInterceptor.intercept (DateTextFieldInterceptor.java:133)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:249)

At org.apache.struts2.interceptor.CheckboxInterceptor.intercept (CheckboxInterceptor.java:89)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:249)

At org.apache.struts2.interceptor.FileUploadInterceptor.intercept (FileUploadInterceptor.java:243)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:249)

At com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept (ModelDrivenInterceptor.java:101)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:249)

At com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept (ScopedModelDrivenInterceptor.java:142)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:249)

At com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept (ChainingInterceptor.java:160)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:249)

At com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept (PrepareInterceptor.java:175)

At com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept (MethodFilterInterceptor.java:99)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:249)

At org.apache.struts2.interceptor.I18nInterceptor.intercept (I18nInterceptor.java:121)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:249)

At org.apache.struts2.interceptor.ServletConfigInterceptor.intercept (ServletConfigInterceptor.java:167)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:249)

At com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept (AliasInterceptor.java:203)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:249)

At com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept (ExceptionMappingInterceptor.java:196)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:249)

At com.gwl.bos.web.interceptor.LoginInterceptor.doIntercept (LoginInterceptor.java:14)

At com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept (MethodFilterInterceptor.java:99)

At com.opensymphony.xwork2.DefaultActionInvocation.invoke (DefaultActionInvocation.java:249)

At org.apache.struts2.factory.StrutsActionProxy.execute (StrutsActionProxy.java:48)

At org.apache.struts2.dispatcher.Dispatcher.serviceAction (Dispatcher.java:574)

At org.apache.struts2.dispatcher.ExecuteOperations.executeAction (ExecuteOperations.java:79)

At org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.doFilter (StrutsPrepareAndExecuteFilter.java:141)

At org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:193)

At org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:166)

At org.springframework.orm.hibernate5.support.OpenSessionInViewFilter.doFilterInternal (OpenSessionInViewFilter.java:155)

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:200)

At org.apache.catalina.core.StandardContextValve.invoke (StandardContextValve.java:96)

At org.apache.catalina.authenticator.AuthenticatorBase.invoke (AuthenticatorBase.java:490)

At org.apache.catalina.core.StandardHostValve.invoke (StandardHostValve.java:139)

At org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:92)

At org.apache.catalina.valves.AbstractAccessLogValve.invoke (AbstractAccessLogValve.java:678)

At org.apache.catalina.core.StandardEngineValve.invoke (StandardEngineValve.java:74)

At org.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.java:343)

At org.apache.coyote.http11.Http11Processor.service (Http11Processor.java:408)

At org.apache.coyote.AbstractProcessorLight.process (AbstractProcessorLight.java:66)

At org.apache.coyote.AbstractProtocol$ConnectionHandler.process (AbstractProtocol.java:836)

At org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun (NioEndpoint.java:1747)

At org.apache.tomcat.util.net.SocketProcessorBase.run (SocketProcessorBase.java:49)

At java.base/java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128)

At java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628)

At org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run (TaskThread.java:61)

At java.base/java.lang.Thread.run (Thread.java:834)

Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.gwl.bos.model.Region.subareas, could not initialize proxy-no Session

At org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException (AbstractPersistentCollection.java:602)

At org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded (AbstractPersistentCollection.java:217)

At org.hibernate.collection.internal.AbstractPersistentCollection.initialize (AbstractPersistentCollection.java:581)

At org.hibernate.collection.internal.AbstractPersistentCollection.read (AbstractPersistentCollection.java:148)

At org.hibernate.collection.internal.PersistentSet.hashCode (PersistentSet.java:458)

At java.base/java.util.HashMap.hash (HashMap.java:339)

At java.base/java.util.HashMap.put (HashMap.java:607)

At java.base/java.util.HashSet.add (HashSet.java:220)

At net.sf.json.AbstractJSON.addInstance (AbstractJSON.java:63)

At net.sf.json.JSONArray._fromCollection (JSONArray.java:1035)

At net.sf.json.JSONArray.fromObject (JSONArray.java:123)

At net.sf.json.AbstractJSON._processValue (AbstractJSON.java:240)

At net.sf.json.JSONObject._processValue (JSONObject.java:2655)

At net.sf.json.JSONObject.processValue (JSONObject.java:2721)

At net.sf.json.JSONObject.setInternal (JSONObject.java:2736)

At net.sf.json.JSONObject.setValue (JSONObject.java:1424)

At net.sf.json.JSONObject.defaultBeanProcessing (JSONObject.java:765)

... 106 more

Solution: set lazy= "false" in & (the default option is lazy= "proxy")

At this point, the study of "can only solve the failed to lazily initialize a collection of role problem in Java" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 285

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report