Problema Hiibernate + JSF [AINDA NAO RESOLVIDO]

6 respostas
jeloy

Boa Tarde…

estou tendo dificuldade para listar uma tabela do bd numa página JSF…

segue abaixo as classes…

DAO

public class DAO {

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("AFEPU");
    EntityManager em = emf.createEntityManager();

    
}

NFeDAO

public class NFeDAO extends DAO {

    public List<NF_e> getAll() {
        List<NF_e> nfList = null;
        em.getTransaction().begin();
        Query q = em.createQuery("Select object(nf) from NF_e as nf;");
        nfList = (List<NF_e>) q.getResultList();
               
    return nfList;

   }
}

mBean

@ManagedBean
@SessionScoped
public class NFeBean {

    private NF_e nfe;

    /**
     * @return the nfe
     */
    public NF_e getNfe() {
        return nfe;
    }

    /**
     * @param nfe the nfe to set
     */
    public void setNfe(NF_e nfe) {
        this.nfe = nfe;
    }

    public List<NF_e> getAll() {
        NFeDAO dao = new NFeDAO();
        List<NF_e> allNotes = dao.getAll();

        for (NF_e notas : allNotes) {

            nfe.setId(notas.getId());
            nfe.setChaveDeAcesso(notas.getChaveDeAcesso());
            
        }

    return allNotes;
    }

Página xHTML

<ui:define name="content">
                <h:form>
                    <h:dataTable value="#{nFeBean.all}" var="nf">
                    <h:column>
                        <h:outputText value="#{nf.chaveDeAcesso}" />



                    </h:column>
                    </h:dataTable>
                    
                </h:form>

Excepion

[PersistenceUnit: AFEPU] Unable to build EntityManagerFactory

javax.persistence.PersistenceException: [PersistenceUnit: AFEPU] Unable to build EntityManagerFactory
	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
	at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:78)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
	at jdbc.DAO.<init>(DAO.java:18)
	at jdbc.NFeDAO.<init>(NFeDAO.java:18)
	at bean.NFeBean.getAll(NFeBean.java:44)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at javax.el.BeanELResolver.getValue(BeanELResolver.java:302)

alguem me diz aonde to errando pelo amor de Deus!

6 Respostas

Flavio_machine

Confere as configurações do arquivo percistense.xml.

jeloy
<?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="AFEPU" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>plinio</jta-data-source>
    <class>modelo.NF_e</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="hibernate.hbm2ddl.auto" value="update"/>
    </properties>
  </persistence-unit>
</persistence>

hibernate.cfg

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/plinio</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">Kdams46sa</property>
    <property name="hibernate.show_sql">true</property>
    <mapping class="modelo.NF_e" package="modelo"/>
  </session-factory>
</hibernate-configuration>
jeloy

up

jeloy

alguem?

R

Pq vc tem o persistence e o hibernate.cfg?Pq n deixar tudo no persistence.xml?

LPJava

bem eu acho que para lista no JSF, vc vai precisar de um DataModel que vai conter o resultado de sua query.

dar uma olhada: http://blog.camilolopes.com.br/category/jsf/page/4/

flw.

Criado 31 de janeiro de 2011
Ultima resposta 3 de fev. de 2011
Respostas 6
Participantes 4