3

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

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

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

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

我使用 Glassfish 3.1.2、Eclipselink 2.3 作为 JPA 提供程序、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)

非常感谢任何帮助。我在这个问题上完全陷入僵局一个多星期了:-(

提前谢谢了!

4

1 回答 1

2

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

于 2012-05-24T20:17:58.563 回答