JPA - Duvida

6 respostas
vjfenix

Estou utilizando JPA para persistir no BD mas está me dando um erro… alguém saberia me dizer o que pode estar acontencendo… segue erro abaixo:

Dei uma olhada no screencast da caelum mas não consegui resolver esse erro

2:32:51,475  INFO Version:15 - Hibernate Annotations 3.3.0.GA

12:32:51,850  INFO Environment:514 - Hibernate 3.2.5

12:32:51,943  INFO Environment:547 - hibernate.properties not found

12:32:52,037  INFO Environment:681 - Bytecode provider name : cglib

12:32:52,240  INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling

12:32:53,318  INFO Version:15 - Hibernate EntityManager 3.3.1.GA

12:32:53,709  INFO Ejb3Configuration:210 - Could not find any META-INF/persistence.xml file in the classpath

Exception in thread main javax.persistence.PersistenceException: No Persistence provider for EntityManager named jpa_hibernate

at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)

at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)

at br.com.junior.jpa.hibernate.GenerateDatabase.main(GenerateDatabase.java:13)

no diretorio do src está da seguinte forma: E:\Hibernate\jpa_hibernate\src\META-INF\persistence.xml

6 Respostas

Pedrosa

Verifique se o nome da base de dados realmente é esse jpa_hibernate definido no arquivo persistence.xml.

<persistence-unit name="jpa_hibernate">
recoma

Adicionando:

:arrow: Todas as libs estão corretamente presentes no classpath?

vhuzalo

Posta o teu persistence.xml para a gente dar uma olhada!

:thumbup:

vjfenix
[quote=vhuzalo]Posta o teu persistence.xml para a gente dar uma olhada!

:thumbup:[/quote]

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;   
&lt;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"&gt;   
  &lt;persistence-unit name="jpa_hibernate" transaction-type="RESOURCE_LOCAL"&gt;   
    &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;   
    &lt;class&gt;br.com.junior.jpa.hibernate.User&lt;/class&gt;   
    &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;   
    &lt;properties&gt;   
      &lt;property name="hibernate.show_sql" value="true"/&gt;   
      &lt;!-- cuidado com essa propriedade, pesquise sobre ela --&gt;   
      &lt;property name="hibernate.hbm2ddl.auto" value="create"/&gt;   
      &lt;property name="hibernate.query.substitutions" value="true=1, false=0"/&gt;           
         
      &lt;property name="hibernate.connection.url" value="jdbc:mysql://localhost/jpa_hibernate"/&gt;   
      &lt;property name="hibernate.connection.username" value="root"/&gt;   
      &lt;property name="hibernate.connection.password" value=""/&gt;   
      &lt;property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/&gt;   
      &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/&gt;   
       
      &lt;property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/&gt;   
         
    &lt;/properties&gt;   
  &lt;/persistence-unit&gt;   
&lt;/persistence&gt; 
**********************************************************************
dei uma olhada e agora está me dando esse erro:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named jpa_hibernate
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
	at br.com.junior.jpa.hibernate.GenerateDatabase.main(GenerateDatabase.java:13)
[code]
vjfenix

Pedrosa:
Verifique se o nome da base de dados realmente é esse jpa_hibernate definido no arquivo persistence.xml.

<persistence-unit name="jpa_hibernate">

esta ok !!!

<persistence-unit name="jpa_hibernate" transaction-type="RESOURCE_LOCAL">
vhuzalo

Pelo visto teu xml está ok, dá uma olhada se tu colocou todos os jar das dependências do hibernate, eu já passei pelo mesmo problema, o hibernate contém muitas dependências e fica difícil de encontrar qual falta.

Uma dica, ao invés de usar o Hibernate, tenta o Toplink, possui 2 ou 3 jars, e como tu tá usando jpa, não vai fazer muita diferença

:thumbup:

Criado 6 de novembro de 2007
Ultima resposta 9 de nov. de 2007
Respostas 6
Participantes 4