Search code examples
javahibernatespringjpaspring-json

How to force Initialize a Hibernate JPA proxy to use it in a JSON call


I have a Spring 3 + JPA 2.0 application. In my @Controller I need an initialized object, but I have proxies , I need to be able to initialize it programmatically. I need functionality similar to org.hibernate.Hibernate.initialize(Object) .

Can someone help . The object is used for AJAX operations. If the properties are proxies I cannot send it as JSON


Solution

  • No JPA option to my knowledge. You should use Hibernate.initialize(..).

    In fact, when I took a look at the hibernate implementation, lazy collections appear to be initialized in many cases that one wouldn't expect. Like entityManager.contains(..) and Persistence.getPersistenceUtil().isLoaded(...). Give these a try, but I don't think you should rely on such implementation details.