Problems with datatable

0

I have a datatable that collects all the data stored in a database table, this table of the database has 2 foreign keys and which are associated by their respective ID, the point is that when running the What I want is not to see the ID of the foreign table but the name associated with that identifier, I have tried it in several ways and I have not achieved good results, I attach part of my code:

<p:panel>
    <h:panelGrid columns="4" style="width: 100%; text-align: center;">
        <h:outputLabel value="DOCENTE"/>
        <p:selectOneMenu value="#{profesorporgradoBean.ppg.profesor}">
            <f:selectItems value="#{profesorBean.listaProfesor}" var="profe" 
                itemValue="#{profe.codprofesor}" itemLabel="#{profe.nombre}"/>
        </p:selectOneMenu>

        <h:outputLabel value="ASIGNAR AL GRADO"/>
        <p:selectOneMenu value="#{profesorporgradoBean.ppg.grado}">
            <f:selectItems value="#{gradoBean.lista}" var="grado" 
                itemValue="#{grado.codgrado}" itemLabel="#{grado.nombre}"/>
        </p:selectOneMenu>
    </h:panelGrid>

</p:panel>

<h:form id="formPrincipal">
    <p:dataTable value="#{profesorporgradoBean.lista}" var="l" rows="10" paginator="true" id="tblPrinciapl">
        <p:column headerText="ID">
            <h:outputLabel value="#{l.codprofesorporgrado}"/>
        </p:column>

        <p:column headerText="IDPROFESOR">
            <h:outputLabel value="#{l.profesor.codprofesor}"/>
            <h:outputLabel value="#{l.profesor.nombre}"/>
        </p:column>

        <p:column headerText="IDGRADO">
            <h:outputLabel value="#{l.grado.codgrado}"/>
            <h:outputLabel value="#{l.grado.nombre}"/>
        </p:column>

        <p:column headerText="AÑO">
            <h:outputLabel value="#{l.anio}"/>
        </p:column>

    </p:dataTable>
</h:form>

These lines are what are causing me the error:

outputLabel value="#{l.profesor.nombre}"

Here the code of my bean for sight

@Named(value = "profesorporgradoBean")
@ViewScoped
public class profesorporgradoBean implements Serializable {

    private boolean enabled;
    private List<Profesorporgrado> lista;
    private Profesor profesor;
    private Grado grado;
    private Profesorporgrado ppg;

    private Integer codProfesor;
    private Integer codGrado;


    public profesorporgradoBean() {
        profesor = new Profesor();
        grado = new Grado();
        ppg = new Profesorporgrado();
    }


   //Getter y Setters

    public List<Profesorporgrado> getLista() {

        profesorporgradoDao pgDao = new profesorporgradoDaoImp();
        lista = pgDao.BuscarTodos();

        return lista;
    }

    public void setLista(List<Profesorporgrado> lista) {
        this.lista = lista;
    }
}

The trace that launches me is the following

  

FATAL: JSF1073: javax.el.ELException has been intercepted during the   RENDER_RESPONSE 6 processing: UIComponent-ClientId =,   Message = / Views / teacher / profexgrado.xhtml @ 50.74   value="# {l.professor.name}":   org.hibernate.LazyInitializationException: could not initialize proxy   - no Session FATAL: /Vistas/profesor/profexgrado.xhtml @ 50,74 value="# {l.profesor.nombre}":   org.hibernate.LazyInitializationException: could not initialize proxy   - no Session javax.el.ELException: /Vistas/profesor/profexgrado.xhtml @ 50,74 value="# {l.profesor.nombre}":   org.hibernate.LazyInitializationException: could not initialize proxy   - no Session at co

my entity professorporgrado is the following

package com.model;
// Generated 22/04/2017 06:11:52 AM by Hibernate Tools 4.3.1


import java.util.Date;

/**
 * Profesorporgrado generated by hbm2java
 */
public class Profesorporgrado  implements java.io.Serializable {


     private Integer codprofesorporgrado;
     private Grado grado;
     private Profesor profesor;
     private String anio;
     private Date fecha;

    public Profesorporgrado() {
    }

    public Profesorporgrado(Grado grado, Profesor profesor, String anio, Date fecha) {
       this.grado = grado;
       this.profesor = profesor;
       this.anio = anio;
       this.fecha = fecha;
    }

    public Integer getCodprofesorporgrado() {
        return this.codprofesorporgrado;
    }

    public void setCodprofesorporgrado(Integer codprofesorporgrado) {
        this.codprofesorporgrado = codprofesorporgrado;
    }
    public Grado getGrado() {
        return this.grado;
    }

    public void setGrado(Grado grado) {
        this.grado = grado;
    }
    public Profesor getProfesor() {
        return this.profesor;
    }

    public void setProfesor(Profesor profesor) {
        this.profesor = profesor;
    }
    public String getAnio() {
        return this.anio;
    }

    public void setAnio(String anio) {
        this.anio = anio;
    }
    public Date getFecha() {
        return this.fecha;
    }

    public void setFecha(Date fecha) {
        this.fecha = fecha;
    }




}

This is the method that makes the query to the teacher table of the database is

public Profesor buscarporId(Session session, Integer codProfesor) {
       String hql = "FROM Profesor WHERE codProfesor = :codProfesor";
       Query q = session.createQuery(hql);
       q.setParameter("codProfesor", codProfesor);

       return (Profesor) q.uniqueResult();
    }
    
asked by Hildemy Borely 18.05.2017 в 23:47
source

0 answers