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)
完整代码