Exception in thread "AWT-EventQueue-0" 2008-02-21 11:28:05,951 ERROR org.hibernate.LazyInitializationException:19 -> could not initialize proxy - no Session
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
Spring框架
用Hibernate取数据,相应的数据结构是:
class Delivery{
List deliveryItems;
Order order;
}
class Order{
List orderItems;
}
class OrderItem/DeliveryItem{
Ware ware;
BigDecimal amount;
}然后,使用一下HQL取数据:
from Delivery d
left join fetch deliveryItems di
left join fetch di.ware
left join fetch d.order o
left join fetch o.orderItems oi
left join fetch oi.ware
取出来的数据有问题了,除了开头那个异常。
Debug进去查看数据发现某个orderItem没有load出来ware(显示时带$的class,各个field是null)。
问题:
总共有7个items的,为什么只有一个没有load出来呢?
7个item关联的ware除了sid,名字不一样以外,都是一样的:基本可以排除非法数据的原因了吧。
这个问题以前也见过,找不到原因,是单独在fetch一下ware暂时解决的。
在这提出这个问题,看看版主及各位达人有什么建议没?
谢谢关注~