Fala galera tudo bem?
Estou estudando JSF com JPA através de um livro, estou no tópico de criação da tabela no banco MySQL através da minha classe de entidade. Estou usando a IDE NetBeans 7.3. Criei no meu projeto JSF, o arquivo persistence.xml no classpath, declarei as tags de configuração, porém quando utilizo propriedades que incluam <property name="javax.persistence.jdbc...
a minha aplicação apresenta o seguinte erro quando rodo a classe main de teste:
Exception in thread "main" java.lang.UnsupportedOperationException: The user must supply a JDBC connection
at org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:30)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:38)
at br.com.caelum.projetoebook.automoveis.teste.PersistidorDeAutomoveis.main(PersistidorDeAutomoveis.java:27)
Java Result: 1
Quando utilizo propriedades do Hibernate como <property name="hibernate.connection...
a aplicação roda normalmente.
Como estou estudando Hibernate, está tudo bem por eu usar as bibliotecas do Hibernate, mais por curiosidade, gostaria de saber como vou conseguir rodar essa aplicação utilizando a da biblioteca javax.persistence. Testei as bibliotecas JPA do Netbeans nenhuma funcionou.
Segue como está a minha estrutura que apresenta o erro:
PERSISTENCE.XML:
<persistence>
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/automoveis"/>
<property name="javax.persistence.jdbc.username" value="root"/>
<property name="javax.persistence.jdbc.password" value="*****"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
MINHA CLASSE MAIN QUE RODA O TESTE:
package br.com.caelum.projetoebook.automoveis.teste;
import br.com.caelum.projetoebook.automoveis.Automovel;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
public class PersistidorDeAutomoveis {
public static void main(String [] args){
EntityManagerFactory emg = Persistence.createEntityManagerFactory("default");
EntityManager em = emg.createEntityManager();
Automovel auto = new Automovel();
auto.setAnoFabricacao(2010);
auto.setModelo("Ferrari");
auto.setObservacoes("Nunca foi batido");
EntityTransaction tx = em.getTransaction();
tx.begin();
em.persist(auto);
tx.commit();
em.close();
emg.close();
}
}
Obrigado desde já!
Troque o nome do arquivo de configuração para persistence.xml ao invés de properties.xml
Opa, então hugo.hlcxcx aqui eu citei errado, mais o nome do meu arquivo está como persistece.xml mesmo!
Faltou definir o provider no persistence.xml
Opa, tudo bem Herbert?
Então, realmente meu persistence.xml não possuía esse parâmetro, após a sua informação, eu o adicionei. Segue a minha estrutura completa:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/automoveis"/>
<property name="javax.persistence.jdbc.password" value="******"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
Porém, quando vou rodar a minha main de teste, ocorre o seguinte erro:
SEVERE: could not complete schema update
java.lang.UnsupportedOperationException: The user must supply a JDBC connection
at org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:30)
at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:27)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:127)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:314)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at br.com.caelum.projetoebook.automoveis.util.JPAUtil.<clinit>(JPAUtil.java:16)
at br.com.caelum.projetoebook.automoveis.teste.PersistidorDeAutomoveis.main(PersistidorDeAutomoveis.java:24)
Exception in thread "main" java.lang.UnsupportedOperationException: The user must supply a JDBC connection
at org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:30)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:38)
at br.com.caelum.projetoebook.automoveis.teste.PersistidorDeAutomoveis.main(PersistidorDeAutomoveis.java:32)
Java Result: 1
Tenho todas as bibliotecas necessárias no meu projeto, tanto que quando troco todas as properties para as do Hibernate funciona legal. Mas desse modo, não funciona. Na minha classe main de teste, todas as importações de persistência são da biblioteca javax.persistence.
Coloque um código que funcione aqui e o que está dando erro, por favor.
Opa, beleza Herbert?
Segue:
FUNCIONA:
PERSISTENCE.XML:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/automoveis"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="******"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
CLASSE ENTIDADE AUTOMOVEL:
package br.com.caelum.projetoebook.automoveis;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
*
* @author Flávio Mendes
*/
@Entity
public class Automovel {
@Id @GeneratedValue
private Long id;
private String marca;
private String modelo;
private Integer anoFabricacao;
private Integer anoModelo;
private String observacoes;
public Long getId() {
return id;
}
public void setId(Long id){
this.id = id;
}
public String getMarca() {
return marca;
}
public void setMarca(String marca) {
this.marca = marca;
}
public String getModelo() {
return modelo;
}
public void setModelo(String modelo) {
this.modelo = modelo;
}
public Integer getAnoFabricacao() {
return anoFabricacao;
}
public void setAnoFabricacao(Integer anoFabricacao) {
this.anoFabricacao = anoFabricacao;
}
public Integer getAnoModelo() {
return anoModelo;
}
public void setAnoModelo(Integer anoModelo) {
this.anoModelo = anoModelo;
}
public String getObservacoes() {
return observacoes;
}
public void setObservacoes(String observacoes) {
this.observacoes = observacoes;
}
}
MANAGED BEAN AUTOMOVELBEAN:
package br.com.caelum.projetoebook.automoveis;
import br.com.caelum.projetoebook.automoveis.util.JPAUtil;
import javax.faces.bean.ManagedBean;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
/**
*
* @author Flávio Mendes
*/
@ManagedBean
public class AutomovelBean {
private Automovel automovel = new Automovel();
public Automovel getAutomovel() {
return automovel;
}
public void setAutomovel(Automovel automovel) {
this.automovel = automovel;
}
//MÉTODOS
public void salva(){
EntityManager em = JPAUtil.getEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
em.persist(automovel);
tx.commit();
em.close();
}
}
JPAUTIL:
package br.com.caelum.projetoebook.automoveis.util;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
/**
*
* @author Flávio Mendes
*/
public class JPAUtil {
private static final EntityManagerFactory emf = Persistence.createEntityManagerFactory("default");
public static EntityManager getEntityManager(){
return emf.createEntityManager();
}
}
CLASSE MAIN DE TESTE PERSISTIDORDEAUTOMOVEIS:
package br.com.caelum.projetoebook.automoveis.teste;
import br.com.caelum.projetoebook.automoveis.Automovel;
import br.com.caelum.projetoebook.automoveis.util.JPAUtil;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
/**
*
* @author Flávio Mendes
*/
public class PersistidorDeAutomoveis {
public static void main(String [] args){
EntityManager em = JPAUtil.getEntityManager();
Automovel auto = new Automovel();
auto.setAnoFabricacao(2010);
auto.setModelo("Ferrari");
auto.setObservacoes("Nunca foi batido");
EntityTransaction tx = em.getTransaction();
tx.begin();
em.persist(auto);
tx.commit();
em.close();
}
}
Dá erro apenas quando eu mudo as propriedades do arquivo persistence.xml confome meu último post aqui. Não mudo nada na minha implementação de classes.
Valeu!
Faltou colocar aqui o que funciona.
Coloca só os dois persistences.
Opa, segue ai:
NÃO FUNCIONA:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/automoveis"/>
<property name="javax.persistence.jdbc.password" value="******"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
FUNCIONA:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/automoveis"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="******"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
Beleza.
Tem como você postar a mensagem de erro completa?
Segue…
run:
24/04/2013 23:34:14 org.hibernate.cfg.annotations.Version <clinit>
INFO: Hibernate Annotations 3.3.1.GA
24/04/2013 23:34:14 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.5
24/04/2013 23:34:14 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
24/04/2013 23:34:14 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
24/04/2013 23:34:14 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
24/04/2013 23:34:15 org.hibernate.ejb.Version <clinit>
INFO: Hibernate EntityManager 3.3.2.GA
24/04/2013 23:34:17 org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: br.com.caelum.projetoebook.automoveis.Automovel
24/04/2013 23:34:17 org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity br.com.caelum.projetoebook.automoveis.Automovel on table Automovel
24/04/2013 23:34:17 org.hibernate.cfg.AnnotationConfiguration secondPassCompile
INFO: Hibernate Validator not found: ignoring
24/04/2013 23:34:17 org.hibernate.connection.UserSuppliedConnectionProvider configure
WARNING: No connection properties specified - the user must supply JDBC connections
24/04/2013 23:34:17 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
24/04/2013 23:34:17 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
24/04/2013 23:34:17 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
24/04/2013 23:34:17 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
24/04/2013 23:34:17 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
24/04/2013 23:34:17 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: disabled
24/04/2013 23:34:17 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
24/04/2013 23:34:17 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
24/04/2013 23:34:17 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
24/04/2013 23:34:17 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
24/04/2013 23:34:17 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
24/04/2013 23:34:17 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
24/04/2013 23:34:17 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
24/04/2013 23:34:17 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
24/04/2013 23:34:17 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
24/04/2013 23:34:17 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
24/04/2013 23:34:17 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: enabled
24/04/2013 23:34:18 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
24/04/2013 23:34:18 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
24/04/2013 23:34:18 org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
24/04/2013 23:34:18 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
24/04/2013 23:34:18 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
24/04/2013 23:34:18 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
24/04/2013 23:34:18 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
24/04/2013 23:34:18 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
24/04/2013 23:34:18 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
24/04/2013 23:34:18 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
24/04/2013 23:34:18 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
24/04/2013 23:34:18 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
24/04/2013 23:34:18 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: Running hbm2ddl schema update
24/04/2013 23:34:18 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: fetching database metadata
24/04/2013 23:34:18 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
SEVERE: could not complete schema update
java.lang.UnsupportedOperationException: The user must supply a JDBC connection
at org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:30)
at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:27)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:127)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:314)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at br.com.caelum.projetoebook.automoveis.util.JPAUtil.<clinit>(JPAUtil.java:16)
at br.com.caelum.projetoebook.automoveis.teste.PersistidorDeAutomoveis.main(PersistidorDeAutomoveis.java:24)
Exception in thread "main" java.lang.UnsupportedOperationException: The user must supply a JDBC connection
at org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:30)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:38)
at br.com.caelum.projetoebook.automoveis.teste.PersistidorDeAutomoveis.main(PersistidorDeAutomoveis.java:32)
Java Result: 1
CONSTRUÍDO COM SUCESSO (tempo total: 6 segundos)
E oq tem aqui: (PersistidorDeAutomoveis.java:32)
Esta é a linha 32 da minha classe PersistidorDeAutomoveis:
tx.begin();
[quote=flavio-mendes]Esta é a linha 32 da minha classe PersistidorDeAutomoveis:
tx.begin();
[/quote]Quem é tx?
É uma EntityTransaction, está na linha 19. Segue a estrutura da classe PersistidorDeAutomoveis:
package br.com.caelum.projetoebook.automoveis.teste;
import br.com.caelum.projetoebook.automoveis.Automovel;
import br.com.caelum.projetoebook.automoveis.util.JPAUtil;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
/**
*
* @author Flávio Mendes
*/
public class PersistidorDeAutomoveis {
public static void main(String [] args){
Automovel auto = new Automovel();
auto.setAnoFabricacao(2010);
auto.setModelo("Ferrari");
auto.setObservacoes("Nunca foi batido");
EntityTransaction tx = em.getTransaction();
tx.begin();
em.persist(auto);
tx.commit();
em.close();
//emg.close();
}
}
Rapaz, me veio uma luz aqui.
Você adicionou a biblioteca EntityManager do hibernate?
Opa! Sim esta biblioteca está no meu projeto. Dei mais uma olhada aqui, tanto a minha classe JPAUtil que carrega a Entidade quanto a classe PersistidorDeAutomoveis que recebe o EntityManager carregado, importam a classe javax.persistence.EntityManager.
[quote=flavio-mendes]Opa! Sim esta biblioteca está no meu projeto. Dei mais uma olhada aqui, tanto a minha classe JPAUtil que carrega a Entidade quanto a classe PersistidorDeAutomoveis que recebe o EntityManager carregado, importam a classe javax.persistence.EntityManager.[/quote]Isso aí é outra coisa. Esse cara aí é da API do JPA, mas não quer dizer que você importou a biblioteca como no pom abaixo:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.0.1.Final</version>
<scope>provided</scope>
</dependency>
Hum! Agora funcionou! Após incluir as suas tags no meu web.xml e voltar as tags javax.persistence no meu persistence.xml para testar com a classe PersistidorDeAutomoveis, deu certo! Agora, só como curiosidade, esse é o melhor caminho para implementar JPA nos projetos então? (tudo configurado dentro do persistence.xml):
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/automoveis"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="******"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
Muito obrigado Herbert!
A melhor prática é utilizar para senha, driver e tals as configurações como abaixo: <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:hibernate"/>
<property name="javax.persistence.jdbc.user" value="sa"/>
<property name="javax.persistence.jdbc.password" value=""/>
Até mais!