Exception in thread "main" java.lang.StackOverflowError
at java.lang.reflect.InvocationTargetException.<init>(InvocationTargetException.java:72)
at sun.reflect.GeneratedMethodAccessor14.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:84)
at com.cpms.entity.Department_$$_jvst20d_0.toString(Department_$$_jvst20d_0.java)
由于采取了热加载(载入时就将引用实体同时载入),在使用toString方法时,陷入死循环。
解决办法:
step1:toString()中可以取消对引用对象的输出;
step2:将热加载载改成懒加载fetch=lazy |