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

时间:2012-05-24 19:38:19

标签: java java-ee jpa lazy-loading eclipselink

我的解决方案包含3个不同的项目:

  • 使用Netbeans自动生成的Facade来管理实体类和persistence.xml的EJB项目

  • 包含所有@Entity注释和静态编织数据库类的类库,以及用于外观ejb的远程接口(在EJB和独立客户端之间共享)

  • 主要由Swing GUI类组成的独立客户端

我使用Glassfish 3.1.2,Eclipselink 2.3作为JPA-provider,Netbeans 7.1.1和MySQL数据库。我配置了一个Ant任务,它根据persistence.xml静态编织我的实体类。

我在使用fetch = FetchType.LAZY装饰的实体之间有几个@OneToOne,@ ManyToOne和@ManyToMany注释关系。

现在我得到了以下错误:

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)

非常感谢任何帮助。我已经完全陷入了这个问题的困境一个多星期了: - (

非常感谢提前!

1 个答案:

答案 0 :(得分:2)

将实体传递给远程客户端后,您无法加载未加载的延迟属性。您需要确保它们在远程传递它们的外观中加载(触摸它们或其他东西)。静态编织与此无关。 (嗯,自动过程与静态/动态/无编织不同 - 但从概念上讲,对于我们来说,开发人员没有区别)