我们正在将应用程序服务器从weblogic10c迁移到glassfish 5。
其中一个应用程序未能在具有以下错误的对象中获取集合。
整个应用程序在Weblogic中运行良好,但是看到了glassfish的问题。是否需要进行配置才能在glassfish中启用Eclipselink或Lazyloading?
[2018-12-03T14:45:47.606-0600] [glassfish 5.0] [FATAL] []
[javax.enterprise.resource.webcontainer.jsf.context] [tid: _ThreadID=37
_ThreadName=http-listener-2(5)] [timeMillis: 1543869947606] [levelValue:
1100] [[
/protected/sv_request.xhtml @13,246 value="Notes (#
{userManagedBean.noteCount})": Exception [EclipseLink-7242] (Eclipse
Persistence Services - 2.7.0.v20170811-d680af5):
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 relationship is
traversed after serialization. To avoid this issue, instantiate the LAZY
relationship prior to serialization.
javax.el.ELException: /protected/sv_request.xhtml @13,246 value="Notes (#
{userManagedBean.noteCount})": Exception [EclipseLink-7242] (Eclipse
Persistence Services - 2.7.0.v20170811-d680af5):
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 relationship is
traversed after serialization. To avoid this issue, instantiate the LAZY
relationship prior to serialization.
at
com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:119)
javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:200) 在javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:187) 在javax.faces.component.UICommand.getValue(UICommand.java:227) 在org.primefaces.component.commandbutton.CommandButtonRenderer.encodeMarkup(CommandButtonRenderer.java:57) 在org.primefaces.component.commandbutton.CommandButtonRenderer.encodeEnd(CommandButtonRenderer.java:49)
这是我们xhtml视图上的按钮
<p:commandButton id="selectButton" action="#{userManagedBean.editRequest}"
icon="ui-icon-search" title="View">
<f:setPropertyActionListener value="#{row}" target="
{userManagedBean.selectedRequest}" />
</p:commandButton>
此命令按钮将选定的请求对象传递给用户管理的Bean。
网络应用中的托管Bean
import prepay.dsl.persistance.Request;
@ManagedBean(name = "userManagedBean")
@SessionScoped
public class UserManagedBean extends AbstractManagedBean implements
Serializable {
private Request request;
public Request getSelectedRequest() {
return request;
}
public void setSelectedRequest(Request selectedRequest) {
setSelectedRequest(selectedRequest.getRequestId());
}
public String getNoteCount() {
return String.valueOf(request.getNoteCollection() == null ? 0 : request.getNoteCollection().size());
}
public void setSelectedRequest(Integer requestPK) {
this.request = getPrePayFacadeRemote().getRequestByPk(requestPK);
this.approveErrorMessage = null;
this.bypassValue = new BypassValue();
this.emailUnknown = Request.UNKNOWN_CARRIER_EMAIL.equals(request.getVendorContactEmail());
this.selectedVendor = new Vendor(this.request.getVendorId(), this.request.getVendorName(), null, null);
this.currentVendors.add(selectedVendor);
}
上述bean中的setSelectedRequest调用ejb来获取数据。
DSL EJB
@Stateless(mappedName = "ejb/PrePayFacade")
@Remote
public class PrePayFacadeBean implements PrePayFacadeRemote {
public Request getRequestByPk(Integer requestId) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("Getting request id [%d]", requestId));
}
entityManager.flush();
Request request = entityManager.find(Request.class, requestId);
// Trigger full population
request.getAttachmentCollection();
request.getAuditHistoryCollection();
request.getNoteCollection();
return request;
}
}
getRequestByPk方法从数据库获取数据,并填充注释集合。但是,在获取此Lazy集合时,我仍然看到失败。
这是我们的请求对象
@Entity
public class Request implements Serializable {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "request", fetch =
FetchType.LAZY)
@OrderBy(value = "noteDatetime DESC")
private Collection<Note> noteCollection;
.
.
.
}
persistenxe.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="prepayDS" transaction-type="JTA">
<jta-data-source>jdbc/EnterpriseDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>
</persistence>