How to test whether lazy loaded JPA collection is initialized?

前端 未结 3 1734
时光说笑
时光说笑 2020-12-04 21:05

I have a service that gets a JPA entity from outside code. In this service I would like to iterate over a lazily loaded collection that is an attribute of this entity to see

3条回答
  •  醉酒成梦
    2020-12-04 21:47

    org.hibernate.Hibernate.isInitialized(..)
    

    There is no standard JPA solution to my knowledge. But if you want to actually initialize collections, you can create an utility method and iterate them (only one iteration is enough).

提交回复
热议问题