Fala pessoal, blza?
Aki, to com um problema: to desenvolvendo em JSF e usando o Hibernate pra persistencia. Qdo eu starto o JBoss, ele encontra o meu persistence.xml, q já revisei inumeras vezes em livros e fóruns, mas na hora de carregar a página dá tilte!! E td começou tentando popular um selectOneMenu q carrega as uf do Brasil.
Códigos:
persistence.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="nomeBanco" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/DefaultDS</jta-data-source>
<class>br.com.****.entidades.Uf</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>
</persistence>
hibernate.cfg.xml
<?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.MySQLInnoDBDialect</property>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/nomeBanco</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">******</property>
</session-factory>
</hibernate-configuration>
o código q gera os selectItem:
public class UfController{
private Uf uf;
private List<Uf> sigla = null;
private SelectItem listaEstado;
public SelectItem getListaEstado() {
getEstados();
return listaEstado;
}
public void setListaEstado(SelectItem listaEstado) {
this.listaEstado = listaEstado;
}
public Uf getUf() {
return uf;
}
public void setUf(Uf uf) {
this.uf = uf;
}
public List<Uf> getSigla() {
return sigla;
}
public void setSigla(List<Uf> sigla) {
this.sigla = sigla;
}
@SuppressWarnings("unchecked")
public void getEstados(){
EntityManagerFactory emf = Persistence.createEntityManagerFactory("erpjrfp");
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
List<Uf> estados = em.createNamedQuery("Uf.findAll").getResultList();
for (Object u : estados) {
Uf uf = (Uf) u;
listaEstado = new SelectItem(uf.getIdUf(), uf.getSiglaEstado(), uf.getNomeEstado());
}
setListaEstado(listaEstado);
}
}
e o erro:
javax.persistence.PersistenceException: [PersistenceUnit: erpjrfp] 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:52)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
at br.com.****.controller.UfController.getEstados(UfController.java:56)
at br.com.****.controller.UfController.getListaEstado(UfController.java:26)
(...)
Caused by: org.hibernate.HibernateException: The chosen transaction strategy requires access to the JTA TransactionManager
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:361)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
(...)
Caused by: javax.el.ELException: /forms/cadFornecedor.xhtml @34,58 value="#{ufController.listaEstado}": Error reading 'listaEstado' on type br.com.****.controller.UfController
at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:76)
at javax.faces.component.UISelectItems.getValue(UISelectItems.java:141)
at com.sun.faces.renderkit.RenderKitUtils.getSelectItems(RenderKitUtils.java:289)
(...)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: nomeBanco] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
(...)
Acho q isso é td oq vcs precisam. Se precisarem de mais me falem.
Vlw!!!