EclipseLink-7242: ValidationException

I got the below exception from EclipseLink that i am not able to find where is the problem. It occurs when trying to edit the main entity with the related attribute that is causing the problem. The error displayed is “Unfetched Attribute Access Error” but i am pretty sure i have included the attribute in the view (as i’m able to edit some other instances but not all)… Can anyone please help to point me to the direction on this kind of the problem?


Exception [EclipseLink-7242] (Eclipse Persistence Services - 2.6.2.cuba6): org.eclipse.persistence.exceptions.ValidationException
Exception Description: An attempt was made to traverse a relationship using indirection that had a null Session.  
This often occurs when an entity with an uninstantiated LAZY relationship is serialized and that relationship is traversed after serialization.  
To avoid this issue, instantiate the LAZY relationship prior to serialization.

I just managed to solve the problem after having another go at it.

The problem is related to View!! Somehow there was a conflict in the views between the nested datasource views and collectiondatasource views that were used in the same edit screen. I’m not sure why but it solve the problem.

On the topic of views, my situation is getting complicated as the views are getting complex. On one of my edit screen which is quite complex, i am worry as it’s taking some time to load (> 5 seconds). Just thought if someone can share any tips or best practices on system performance improvement.

If you load an object graph that includes multiple levels of collections, try to split your view and the corresponding datasources tree. For example, imagine that you have the following structure:


<datasource id="airportDs" class="Airport" view="airport-full">
    <collectionDatasource id="terminalsDs" property="terminals">
        <collectionDatasource id="meetingPointsDs" property="meetingPointsDs"/>
    </collectionDatasource>
</datasource>

Here an Airport + collection of Terminals + collections of Meeting Points for each Terminal are loaded at once. At the same time, probably only the Airport and the collection of Terminals are displayed on the screen at once. Displaying Meeting Points makes sense only for a selected Terminal, not for all. So why to load them all at once? Even if the loading on the database level is performed in batches (first SQL for Airport, second for all Terminals, third for all Meeting Points of all Terminals), the amount of data is excessive - you don’t need all meeting points at once.

In this case, you could improve performance if you make meetingPointsDs a standalone datasource:


<datasource id="airportDs" class="Airport" view="airport-full">
    <collectionDatasource id="terminalsDs" property="terminals"/>
</datasource>

<collectionDatasource id="meetingPointsDs" property="meetingPointsDs">
    <query>select e from sample$MeetingPoint e where e.terminal.id = :ds$terminalsDs</query>
</collectionDatasource>

So you will load only the data required on the screen at the moment: Airport, all its Terminals, and all Meeting Points for a selected Terminal.

Keep in mind though that nested datasources are required for editing compositions. For all other cases with collections consider using standalone linked datasources as described above. And the performance gain can be much bigger if you have a collection of Airports on the top level.

Thanks, Konstantin. Cheers.