Hello everyone, I have not yet experienced java and would like help.
I am mapping SEVERAL lists with @ManyToMany (cascade = CascadeType.ALL) and I'm getting the following excpetion when I try to EDIT a record in the DB:
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 not edit it.
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 many component
<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>