RE: Lazy Load of Hibernate doesn't work in Liferay 7.2 DXP

thumbnail
Syed Nasar, modified 5 Years ago. Junior Member Posts: 64 Join Date: 9/3/15 Recent Posts
We are using hibernate for service interaction. (Not service builder)At one model class,  we are using Lazy load as follows:

@OneToOne(orphanRemoval = true, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "SCHOOL_ENROLMENTS_ID")
private final SchoolEnrolments enrolments = new SchoolEnrolments();

It was working fine in Liferay 6.2 but after upgrading to 7.2 DXP,  It returns the following error while trying to accessing this field.

org.hibernate.LazyInitializationException: could not initialize proxy - no Session
    at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:167)
    at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:215)
    at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)


thumbnail
David H Nebinger, modified 5 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
OSGi brings a lot of classloader restrictions and requirements into play. It can be difficult exposing these kinds of things within OSGi.

In 6.2 you had a portlet war file and your hibernate was isolated within the web application. This happens to be a construct that hibernate knows how to operate within. You'll have to stick to the same kind of deployment model to get it to work under 7.x.
thumbnail
Syed Nasar, modified 5 Years ago. Junior Member Posts: 64 Join Date: 9/3/15 Recent Posts
Even in 7.2, we are deploying as a war.
Why difficulty in exposing these kinds of things within OSGi.
And can you provide some examples for implementing Hibernate Lazy load in Liferay 7.2.