Erro usando JPA... No Persistence provider for EntityManager named tarefas

Olá,

estou com erro ao acessar <persistence-unit name=“tarefas”> criei o arquivo embaixo do diretório C:\workspace\ExemploSpring\WebContent\META-INF\persistence.xml

e parece que não está lendo …

ALguém poderia me ajudar…

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class GeraTabelas {
	public static void main(String[] args) {
	    EntityManagerFactory factory = Persistence.createEntityManagerFactory("tarefas");

	    factory.close();
	  }
}
log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named tarefas
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
	at br.com.caelum.tarefas.jpa.GeraTabelas.main(GeraTabelas.java:8)
@SuppressWarnings("deprecation")
@Entity
@Table(name="tarefas")
public class Tarefa {
	@Id
	@GeneratedValue
	private Long id;
	@NotNull 
	@Size(min=5,max=100)
	private String descricao;
	private boolean finalizado;
	@Temporal(TemporalType.DATE)
	private Calendar dataFinalizacao;

&lt;persistence-unit name="tarefas"&gt;

   &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;

   &lt;class&gt;br.com.xxxxxx.tarefas.modelo.Tarefa&lt;/class&gt;

   &lt;properties&gt;
    &lt;!-- dados da conexao --&gt;
   &lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /&gt;
  &lt;property name="javax.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1/agenda" /&gt;
  &lt;property name="javax.persistence.jdbc.user" value="root" /&gt;
  &lt;property name="javax.persistence.jdbc.password" value="paulo" /&gt;
  &lt;!-- SEM as propriedades URL, login, senha e driver --&gt;

  &lt;property name="hibernate.dialect" 
              value="org.hibernate.dialect.MySQL5InnoDBDialect" /&gt;
  &lt;property name="hibernate.show_sql" value="true" /&gt;
  &lt;property name="hibernate.format_sql" value="true" /&gt;
  &lt;property name="hibernate.hbm2ddl.auto" value="update" /&gt;    
   &lt;/properties&gt;
 &lt;/persistence-unit&gt;

&lt;/persistence&gt;

Onde você colocou o persistence.xml?

olá,

criei o diretório META-INF embaixo do pcote src e ai funcionou…

mais agora está me dando esse erro

log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.NoSuchFieldError: TRACE
	at org.jboss.logging.Log4jLogger.translate(Log4jLogger.java:64)
	at org.jboss.logging.Log4jLogger.doLog(Log4jLogger.java:44)
	at org.jboss.logging.Logger.trace(Logger.java:128)
	at org.hibernate.ejb.internal.EntityManagerMessageLogger_$logger.trace(EntityManagerMessageLogger_$logger.java:432)
	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:323)
	at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
	at br.com.caelum.tarefas.jpa.GeraTabelas.main(GeraTabelas.java:8)

Verifique se os seus jars estão corretos.

Olá,

como saberei que está correto meus jars ???

estou usando esses


antlr-2.7.7.jar
commons-logging-1.0.4.jar
dom4j-1.6.1
hibernate-commons-annotations-4.0.1.Final
hibernate-core-4.1.10.Final
hibernate-entitymanager-4.1.10.Final
hibernate-jpa-2.0-api-1.0.1.Final
hibernate-validator-4.2.0.Final
javassist-3.15.0-GA
jboss-logging-3.1.0.GA
jboss-transaction-api_1.1_spec-1.0.0.Final
log4j-1.2.6
slf4j-api-1.6.2
slf4j-log4j12-1.6.2
spring-aop-3.2.2.RELEASE
spring-aspects-3.2.2.RELEASE
spring-beans-3.2.2.RELEASE
spring-context-3.2.2.RELEASE
spring-core-3.2.2.RELEASE
spring-expression-3.2.2.RELEASE
spring-jdbc-3.2.2.RELEASE
spring-orm-3.2.2.RELEASE
spring-web-3.2.2.RELEASE
spring-webmvc-3.2.2.RELEASE

validation-api-1.0.0.GA

como está configurado meu arquivo spring…

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;

	&lt;context:component-scan base-package="br.com.caelum.tarefas" /&gt;
	&lt;mvc:annotation-driven /&gt;

	&lt;bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
		&lt;property name="prefix" value="/WEB-INF/views/" /&gt;
		&lt;property name="suffix" value=".jsp" /&gt;
	&lt;/bean&gt;

	&lt;bean id="entityManagerFactory"
		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
		&lt;property name="dataSource" ref="mysqlDataSource" /&gt;
		&lt;property name="jpaVendorAdapter"&gt;
			&lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" /&gt;
		&lt;/property&gt;
	&lt;/bean&gt;

	&lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
		&lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
	&lt;/bean&gt;

&lt;/beans&gt;

Ahh o seu caso é com o spring e jpa, especifique no topico.
Quando uso o spring eu integro ele ao hibernate e deixo o spring gerenciar as transaction pra mim, com o SessionFactry.

Estava tendo esse erro também, o meu caso era por falta do jar “hibernate-entitymanager-4.2.1.Final.jar” (estou usando a versão 4.2.1).

Mas vi que você já está usando o hibernate-entitymanager.

Confirme se você adicionou ele no classpath do projeto.

[quote=paribe]Olá,

como saberei que está correto meus jars ???

estou usando esses

[code]

antlr-2.7.7.jar
commons-logging-1.0.4.jar
dom4j-1.6.1
hibernate-commons-annotations-4.0.1.Final
hibernate-core-4.1.10.Final
hibernate-entitymanager-4.1.10.Final
hibernate-jpa-2.0-api-1.0.1.Final
hibernate-validator-4.2.0.Final
javassist-3.15.0-GA
jboss-logging-3.1.0.GA
jboss-transaction-api_1.1_spec-1.0.0.Final
log4j-1.2.6
slf4j-api-1.6.2
slf4j-log4j12-1.6.2
spring-aop-3.2.2.RELEASE
spring-aspects-3.2.2.RELEASE
spring-beans-3.2.2.RELEASE
spring-context-3.2.2.RELEASE
spring-core-3.2.2.RELEASE
spring-expression-3.2.2.RELEASE
spring-jdbc-3.2.2.RELEASE
spring-orm-3.2.2.RELEASE
spring-web-3.2.2.RELEASE
spring-webmvc-3.2.2.RELEASE

validation-api-1.0.0.GA

[/code][/quote]