• springboot 出现 org.hibernate.LazyInitializationException: could not initialize proxy


    org.hibernate.LazyInitializationException: could not initialize proxy [com.example.shop.dataobject.User#16] - no Session
    at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:170) ~[hibernate-core-5.4.8.Final.jar:5.4.8.Final]
    at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:310) ~[hibernate-core-5.4.8.Final.jar:5.4.8.Final]
    at org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor.intercept(ByteBuddyInterceptor.java:45) ~[hibernate-core-5.4.8.Final.jar:5.4.8.Final]
    at org.hibernate.proxy.ProxyConfiguration$InterceptorDispatcher.intercept(ProxyConfiguration.java:95) ~[hibernate-core-5.4.8.Final.jar:5.4.8.Final]
    at com.example.shop.dataobject.User$HibernateProxy$VAtYZAqu.toString(Unknown Source) ~[classes/:na]
    at com.example.shop.shiro.UserRealm.doGetAuthorizationInfo(UserRealm.java:39) ~[classes/:na]
    at org.apache.shiro.realm.AuthorizingRealm.getAuthorizationInfo(AuthorizingRealm.java:341) ~[shiro-core-1.4.0.jar:1.4.0]
    at org.apache.shiro.realm.AuthorizingRealm.isPermitted(AuthorizingRealm.java:462) ~[shiro-core-1.4.0.jar:1.4.0]
    at org.apache.shiro.realm.AuthorizingRealm.isPermitted(AuthorizingRealm.java:458) ~[shiro-core-1.4.0.jar:1.4.0]
    at org.apache.shiro.authz.ModularRealmAuthorizer.isPermitted(ModularRealmAuthorizer.java:223) ~[shiro-core-1.4.0.jar:1.4.0]
    at org.apache.shiro.mgt.AuthorizingSecurityManager.isPermitted(AuthorizingSecurityManager.java:113) ~[shiro-core-1.4.0.jar:1.4.0]
    at org.apache.shiro.subject.support.DelegatingSubject.isPermitted(DelegatingSubject.java:162) ~[shiro-core-1.4.0.jar:1.4.0]

    根据日志信息,他指向了 User 实体类,

    是因为懒加载导致的

    解决办法:

    在User实体类上加上 

    @Proxy(lazy=false)
    完整代码

  • 相关阅读:
    Android对话框自定义标题
    JSONObject和JSONArray的关系
    Java的List排序
    重写onStart()函数
    SSH框架执行自己定义的SQL语句
    nested exception is org.hibernate.QueryException: could not resolve property
    java.lang.NullPointerException org.apache.struts2.impl.StrutsActionProxy.getErrorMessage(StrutsActionProxy.java:69)
    Java项目打包部署war文件
    一道腾讯面试题
    SSH服务器与Android通信(3)--Android客户端发送数据
  • 原文地址:https://www.cnblogs.com/pxjbk/p/12057391.html
Copyright © 2020-2023  润新知