Java的EE6:FetchType.LAZY静态编织抛出奇怪异常(Java-EE6: FetchT

2019-09-17 11:50发布

My Solution consists of 3 different projects:

  • EJB project with Netbeans auto-generated Facades to manage Entity classes and the persistence.xml

  • Class-Library that holds all @Entity annotated and statically weaved database classes and the remote interfaces for the facade ejb's (shared between EJB and stand-alone client)

  • Stand-alone Client that consists mainly of Swing GUI classes

I use Glassfish 3.1.2, Eclipselink 2.3 as JPA-provider, Netbeans 7.1.1 and a MySQL database. I configured an Ant-task that statically weaves my entity classes on the basis of the persistence.xml.

I have several @OneToOne, @ManyToOne and @ManyToMany annotated relations between the entities decorated with fetch=FetchType.LAZY.

Now I get all along 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 highly appreciated. I completely got deadlocked with this issue for more than a week now :-(

Many thanks in advance!

Answer 1:

一旦实体被传递到远程客户端 - 你不能负载无加载延迟属性。 你需要确保它们装在远程通过他们的门面(触摸他们或东西)。 静态编织无关与此有关。 (好吧,自动过程与静态/动态/不织布不同 - 但概念上我们作为开发商没有区别)



文章来源: Java-EE6: FetchType.LAZY with static weaving throws strange exception