Error when trying to edit a record: component<p:selectManyCheckbox/> failed to lazily initialize a Collection of role:

Asked

Viewed 158 times

0

Hello personal I have no experience with java and would like to receive help.

I’m mapping SEVERAL lists with @Manytomany(Scade = Cascadetype.ALL) and I’m getting the following excpetion when I try to EDIT a comic book entry :

ago 10, 2017 6:14:40 PM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException GRAVE: Error Rendering View[/seduc/escola/matricula/NovaMatricula.xhtml] org.hibernate.LazyInitializationException: failed to lazily initialize a
collection of role: com.soulsoftware.sisgep.seducMaz.model.Aluno.tipoDeficiencias, could not initialize proxy - no Session at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:575)
at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:214) at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:554) at
org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:142) at org.hibernate.collection.internal.PersistentBag.toArray(PersistentBag.java:300) at org.primefaces.renderkit.SelectManyRenderer.getValues(SelectManyRenderer.java:55)
at org.primefaces.component.selectmanycheckbox.SelectManyCheckboxRenderer.encodeLineLayout(SelectManyCheckboxRenderer.java:246) at org.primefaces.component.selectmanycheckbox.SelectManyCheckboxRenderer.encodeSelectItems(SelectManyCheckboxRenderer.java:233)
at org.primefaces.component.selectmanycheckbox.SelectManyCheckboxRenderer.encodeTabularLayout(SelectManyCheckboxRenderer.java:159) at org.primefaces.component.selectmanycheckbox.SelectManyCheckboxRenderer.encodeMarkup(SelectManyCheckboxRenderer.java:78)
at org.primefaces.component.selectmanycheckbox.SelectManyCheckboxRenderer.encodeEnd(SelectManyCheckboxRenderer.java:55) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:920) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeDynamicBody(PanelGridRenderer.java:131) at org.primefaces.component.panelgrid.PanelGridRenderer.encodeTableBody(PanelGridRenderer.java:102) at org.primefaces.component.panelgrid.PanelGridRenderer.encodeTableLayout(PanelGridRenderer.java:65)
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:37) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:920) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863) at org.primefaces.component.panelgrid.PanelGridRenderer.encodeDynamicBody(PanelGridRenderer.java:131)
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeTableBody(PanelGridRenderer.java:102) at org.primefaces.component.panelgrid.PanelGridRenderer.encodeTableLayout(PanelGridRenderer.java:65) at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:37)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:920) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863) at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:582)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1689) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at org.primefaces.component.api.UITabPanel.visitTree(UITabPanel.java:920) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at javax.faces.component.UIForm.visitTree(UIForm.java:371) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:403) at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:322)
at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:219) at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:57) at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:1004)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856) at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:432) at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:134)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)

In my case I can save the object, but I can’t Edit.

POJO (Student):

@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "aluno_tipo_deficiencia", joinColumns = @JoinColumn(name = "aluno_id"), 
inverseJoinColumns = @JoinColumn(name = "tipo_id"))
public List<TipoDeficiencia> getTipoDeficiencias() {
    return tipoDeficiencias;

The Bean:

@Named

@Viewscoped public class Cadastroalunobean Implements Serializable {

private static final long serialVersionUID = 1L;

@Inject
private CadastroAlunoService cadastroAlunoService;

@Inject
private Escolas escolas;
@Inject
private Turmas turmas;
@Inject
private Series series;
@Inject
private Turnos turnos;
@Inject
private AltasHabilidades altasHabilidades;
@Inject
private AlunosNPDocumentos alunosNPDocumentos;
@Inject
private TiposDeficiencias tiposDeficiencias;
@Inject
private TranstornosGlobais transtornosGlobais;
@Inject
private TiposVeiculos tiposVeiculos;

private Aluno aluno;

private List<Escola> escolasLista;
private List<Turma> turmaLista;
private List<Serie> serieLista;
private List<Turno> turnoLista;
private List<AltaHabilidade> altaHabLista;
private List<AlunoNPDocumento> alunosNPDocLista;
private List<TipoDeficiencia> tipoDeficienciaLista;
private List<TranstornoGlobalDesenvovimento> globalDesenvovimentosLista;
private List<TipoVeiculo> tiposVeiculosLista;

public CadastroAlunoBean() {
    this.limpar();
}

private void limpar() {
    aluno = new Aluno();

}

public void inicializar() {
    if (FacesUtil.isNotPostback()) {
        this.escolasLista = escolas.escolasRepository();
        this.turmaLista = turmas.turmasRepository();
        this.serieLista = series.seriesRepository();
        this.turnoLista = turnos.turnosRepository();
        this.altaHabLista = altasHabilidades.altahablRepository();
        this.alunosNPDocLista = alunosNPDocumentos.alunoNPDocRepository();
        this.tipoDeficienciaLista = tiposDeficiencias.tipoDeficienciaRepository();
        this.globalDesenvovimentosLista = transtornosGlobais.trantornoGlobaslRepository();
        this.tiposVeiculosLista = tiposVeiculos.tipoVeiculoRepository();

    }
}

public void salvar() {
    this.aluno = cadastroAlunoService.salvar(this.aluno);
    this.limpar();
    FacesUtil.addSuccessMessage("Aluno salvo com sucesso!");
}

One of the many components

<p:selectManyCheckbox value="#{cadastroAlunoBean.aluno.alunoNPDocumentos}" converter="alunoNaoPDocumento">
  <f:attribute name="collectionType" value="java.util.ArrayList" />
  <f:selectItems value="#{cadastroAlunoBean.alunosNPDocLista}" var="semDoc" itemLabel="#{semDoc.nome}" itemValue="#{semDoc}" />
</p:selectManyCheckbox>

1 answer

0


The problem is because you are trying to open a Hibernate session from the presentation layer

Add Fetchtype.EAGER to Hibernate to carry the information for you

@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
  • It worked but only right in a model annotation I have 4 attributes with @Manytomany(Scade = Cascadetype.ALL), when I use more than one,@Manytomany(fetch = Fetchtype.EAGER, Scade = Cascadetype.ALL), error when searching: cannot fetch simultaneously Multiple bags. thank you Marquezani. You have a suggestion.

  • Ola Pessoal eu conseguir seguindo a ideia de outro colega na net acrescentando a linha '@Fetch(org.hibernate.annotations.FetchMode.SUBSELECT)' ao '@ManyToMany(fetch=FetchType.EAGER,cascade = CascadeType.ALL)&#xA; @Fetch(org.hibernate.annotations.FetchMode.SUBSELECT)&#xA; @JoinTable(name = "aluno_altaHabl", joinColumns = @JoinColumn(name = "aluno_id"), &#xA; inverseJoinColumns = @Joincolumn(name = "alta_habl_id")) public List<Highskill> getAltasHabilities() { High Recoverability; }'. what do you think? I will lose performance and performance in BD?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.