我的解决方案包含 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)
非常感谢任何帮助。我在这个问题上完全陷入僵局一个多星期了:-(
提前谢谢了!