Java-EE6: FetchType.LAZY with static weaving throws a strange exception

My Solution consists of three different projects:

  • An EJB project with Netbeans Automated Generators to manage Entity and persistence.xml classes

  • A class library that contains all the annotated and statically docked @Entity database classes and remote interfaces for the ejb facade (shared between the EJB and the stand-alone client)

  • A standalone client consisting mainly of Swing GUI classes

I am using Glassfish 3.1.2, Eclipselink 2.3 as a JPA provider, Netbeans 7.1.1 and a MySQL database. I configured Ant -task, which statically drags my persistence.xml-based object classes.

I have several @OneToOne, @ManyToOne and @ManyToMany annotated relationships between objects decorated with fetch = FetchType.LAZY.

Now I get the following errors:

Exception in thread "Mainframe Loader" Local Exception Stack: 
Exception [EclipseLink-7242] (Eclipse Persistence Services - 2.3.2.v20111125-r10461):     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 lazy relationship is traversed after serialization.  To avoid this issue, instantiate the LAZY relationship prior to serialization.
 at org.eclipse.persistence.exceptions.ValidationException.instantiatingValueholderWithNullSession(ValidationException.java:998)
 at org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder.instantiate(UnitOfWorkValueHolder.java:220)
 at org.eclipse.persistence.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:88)
 at org.eclipse.persistence.indirection.IndirectList.buildDelegate(IndirectList.java:244)
 at org.eclipse.persistence.indirection.IndirectList.getDelegate(IndirectList.java:414)
 at org.eclipse.persistence.indirection.IndirectList.size(IndirectList.java:752)
 at ch.lawsuite.gui.mail.PosteingangUI.updateDokumentTable(PosteingangUI.java:47)
 at ch.lawsuite.gui.mail.MailboxUI.updateDokumentTables(MailboxUI.java:81)
 at ch.lawsuite.gui.mail.MailboxUI.initMailboxes(MailboxUI.java:37)
 at ch.lawsuite.gui.mail.MailboxUI.<init>(MailboxUI.java:23)
 at ch.lawsuite.gui.MainframeUI.initModules(MainframeUI.java:191)
 at ch.lawsuite.gui.login.LoginUI$MainframeLoader.run(LoginUI.java:131)

Any help is greatly appreciated. I have completely stalled with this problem for more than a week: - (

Thank you very much in advance!

+3
source share
1 answer

As soon as the object is transferred to the remote client, you cannot load unloaded lazy properties. You need to make sure that they are loaded (tap them or something else) on the facade that transfers them remotely. Static weaving has nothing to do with this. (Well, the automatic process is different with static / dynamic / without weaving - but conceptually for us, as developers, there is no difference)

+2
source

All Articles