cancel
Showing results for 
Search instead for 
Did you mean: 

Loosing entity references with LAZY fetched properties in EAR Project

Former Member
0 Kudos

Hi Experts,

i have the following problem. We have an Enterprise Application with an EJB 3 Package containing stateless session beans for database access and a web application (WAR), based on spring/spring webflow that obtain the stateless bean via JNDI lookup.

The error we are run into is, that when we load entities (eg. "find all projects") with lazy fetched properties (@OneToMany / @ManyToOne) everthing is fine on the EJB-Container (i can see the the list loaded entities in the debugger) but in the web application these references are "null".

I found a workaround by setting the (not needed) lazy properties to "null" before the method call returns (in stateless bean), then the objects will be available in the web application.

Currently i have no clue what happend during the EJB to WAR transition. (I assume that ejb & war are running in the same class loader ... )

Any ideas?

Thanks, Arne

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello,

i think is this because of the Entity Manager Transaction being closed when the EJB call finishes -> In the web application you don´t have an open Transaction so the lazy loaded objects won´t be available

regards franz

Former Member
0 Kudos

Hi together,

because we could't find any solution to this specific problem, we debuged the entire communication between the EJB and the WAR, where the WAR accesses the EJB services via JNDI.

What we found out is, that the JPA implementation of SAP suits not the JPA standard very well. In the case of Entities with LAZY loaded references, the collection is not null in general, in fact the property is filled with vendor specific dummy/proxy objects.

The JPA standard (JSR-220) defines in chapter 3.2.4.2 (Detached Entities and Lazy Loading):

A vendor is required to support the serialization and subsequent deserialization and merging of detached entity instances (which may contain lazy properties or fields and/or relationships that have not been

fetched) back into a separate JVM instance of that vendor's runtime, where both runtime instances have

access to the entity classes and any required vendor persistence implementation classes.

What we figured out is, that the dummy/proxy object of a lazy loaded property contains a class called LazyLoaderImpl. During the communication via JNDI there is a specific process, which creates a copy (clone) of the entity. This is the point, where the LazyLoaderImpl is tried to serialized/deserialized. Because this object is not serializable, an exception arise. Unfortunately, this error is not logged, so it is hard to find out.

The service, which tries to copy the entity is called: com.sap.engine.services.ejb3.runtime.impl.copier.ReflectCopier

The error message is: Class class com.sap.engine.services.orpersistence.core.LazyLoaderImpl is not Serializable

Our solution right now is to write an EJB interceptor, which searches for all lazy fetched properties and replaces them with null values. We have to figure out, if this has other sideeffects.

To be compliant to JSR-220, SAP should ensure, that all objects within the lazy object tree are serializable.