Eclipselink Ленивая ошибка загрузки в Glassfish - PullRequest
0 голосов
/ 04 декабря 2018

Мы переносим наши серверы приложений с weblogic10c на glassfish 5.

Одно из приложений не может получить коллекцию в объекте с ошибкой ниже.

Все это приложение работало нормальнов Weblogic, но видя проблемы с Glassfish.Есть ли какая-либо конфигурация, которую необходимо выполнить, чтобы включить Eclipselink или Lazyloading в Glassfish?

[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.alom. Ual.java: 227) по адресу org.primefaces.component.commandbutton.CommandButtonRenderer.encodeMarkup (CommandButtonRenderer.java:57) по адресу org.primefaces.component.commandbutton.CommandButtonRenderer.encodeEnd (CommandButtonRendere

101) 101* Это кнопка в нашем представлении xhtml

 <p:commandButton id="selectButton" action="#{userManagedBean.editRequest}" 
icon="ui-icon-search" title="View">  
 <f:setPropertyActionListener value="#{row}" target=" 
 {userManagedBean.selectedRequest}" />  
 </p:commandButton> 

Эта командная кнопка передает выбранный запрошенный объект управляемому компоненту.

Управляемый компонент в веб-приложении

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);
}

setSelectedRequest в приведенном выше bean-компоненте вызывает 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>
...