How to convert a Hibernate proxy to a real entity object

后端 未结 10 803
离开以前
离开以前 2020-11-22 16:49

During a Hibernate Session, I am loading some objects and some of them are loaded as proxies due to lazy loading. It\'s all OK and I don\'t want to turn lazy lo

10条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 17:25

    As I explained in this article, since Hibernate ORM 5.2.10, you can do it likee this:

    Object unproxiedEntity = Hibernate.unproxy(proxy);
    

    Before Hibernate 5.2.10. the simplest way to do that was to use the unproxy method offered by Hibernate internal PersistenceContext implementation:

    Object unproxiedEntity = ((SessionImplementor) session)
                             .getPersistenceContext()
                             .unproxy(proxy);
    

提交回复
热议问题