In Spring with jpa/hibernate, how do I keep a session open to avoid lazy initialization exceptions?
问题 I currently mark collections in entity beans as eager to avoid getting a lazy initialization exception when I try to access the collection properties after loading the bean with the EntityManager. If I instead leave the collection as lazy loading, how do I keep a session open? I thought about trying @Transactional, but even if that worked I wouldn't want to do it because it doesn't seem right to leave a transaction open over a long method. 回答1: https://www.hibernate.org/43.html Basically, you