Java.lang.UnsupportedOperationException: The user must supply a JDBC connection

Aew gente, to começando a ver o Hibernate com JPA seguindo a apostila do K19, e ao tentar levantar a conexão já recebi esse erro:

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.SchemaExport.execute(SchemaExport.java:180) at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:311) 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 GeraTabelas.main(GeraTabelas.java:16)

suspeiro q seja o meu persistence.xml, mas não sei o que tem de errado:

persistence.xml dentro da pasta META-INF:

<?xml version="1.0" encoding="UTF-8"?>
<persistence 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"
 version="1.0">

    <persistence-unit name="livraria" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="create"/>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="javax.persistence.jdbc.user" value="root"/>
            <property name="javax.persistence.jdbc.password" value="root"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://172.18.74.67:3306/livraria"/>
        </properties>
    </persistence-unit>

</persistence>

estou criando o projeto pelo netbeans e apenas importei o log4j
os beans estão normais:

Livro:

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author f1831049
 */
@Entity
public class Livro {

    @Id
    @GeneratedValue
    private int id;
    private String nome;
    private double preco;
    private long editora_id;

    public long getEditora_id() {
        return editora_id;
    }

    public void setEditora_id(long editora_id) {
        this.editora_id = editora_id;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public double getPreco() {
        return preco;
    }

    public void setPreco(double preco) {
        this.preco = preco;
    }
}

Editora:

[code]

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class Editora {

@Id
@GeneratedValue
private long id;
private String nome;
private String email;

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public long getId() {
    return id;
}

public void setId(long id) {
    this.id = id;
}

public String getNome() {
    return nome;
}

public void setNome(String nome) {
    this.nome = nome;
}

}[/code]

Seu persistence.xml me parece ok.
Talvez o persistence.xml esteja na pasta errada?
Ele deve estar na pasta META-INF junto das suas classes e não no META-INF do lado da WEB-INF (numa aplicação web).
Se isso estiver correto, pode ser que esteja faltando algum jar?
Tem o restante da exceção? Seria bom ver a causa dela, que pode ser outra coisa.

isso é o q sai no console:

init:
deps-module-jar:
deps-ear-jar:
deps-jar:
compile-single:
run-main:
0 [main] INFO  org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.3.1.GA
11 [main] INFO  org.hibernate.cfg.Environment - Hibernate 3.2.5
14 [main] INFO  org.hibernate.cfg.Environment - hibernate.properties not found
17 [main] INFO  org.hibernate.cfg.Environment - Bytecode provider name : cglib
20 [main] INFO  org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
89 [main] INFO  org.hibernate.ejb.Version - Hibernate EntityManager 3.3.2.GA
2533 [main] WARN  org.hibernate.ejb.packaging.PersistenceXmlLoader - Warning parsing XML: XML InputStream(6) schema_reference.4: Failed to read schema document 'http://java.sun.com/xml/', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
2538 [main] WARN  org.hibernate.ejb.packaging.PersistenceXmlLoader - Warning parsing XML: XML InputStream(8) schema_reference.4: Failed to read schema document 'http://java.sun.com/xml/', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
2540 [main] WARN  org.hibernate.ejb.packaging.PersistenceXmlLoader - Warning parsing XML: XML InputStream(9) schema_reference.4: Failed to read schema document 'http://java.sun.com/xml/', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
2541 [main] WARN  org.hibernate.ejb.packaging.PersistenceXmlLoader - Warning parsing XML: XML InputStream(10) schema_reference.4: Failed to read schema document 'http://java.sun.com/xml/', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
2548 [main] WARN  org.hibernate.ejb.packaging.PersistenceXmlLoader - Warning parsing XML: XML InputStream(11) schema_reference.4: Failed to read schema document 'http://java.sun.com/xml/', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
2550 [main] WARN  org.hibernate.ejb.packaging.PersistenceXmlLoader - Warning parsing XML: XML InputStream(12) schema_reference.4: Failed to read schema document 'http://java.sun.com/xml/', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
2551 [main] WARN  org.hibernate.ejb.packaging.PersistenceXmlLoader - Warning parsing XML: XML InputStream(13) schema_reference.4: Failed to read schema document 'http://java.sun.com/xml/', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
2553 [main] WARN  org.hibernate.ejb.packaging.PersistenceXmlLoader - Warning parsing XML: XML InputStream(14) schema_reference.4: Failed to read schema document 'http://java.sun.com/xml/', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
2559 [main] WARN  org.hibernate.ejb.packaging.PersistenceXmlLoader - Warning parsing XML: XML InputStream(15) schema_reference.4: Failed to read schema document 'http://java.sun.com/xml/', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
2560 [main] WARN  org.hibernate.ejb.packaging.PersistenceXmlLoader - Warning parsing XML: XML InputStream(16) schema_reference.4: Failed to read schema document 'http://java.sun.com/xml/', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
2804 [main] INFO  org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: Editora
2875 [main] INFO  org.hibernate.cfg.annotations.EntityBinder - Bind entity Editora on table Editora
2937 [main] INFO  org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: Livro
2938 [main] INFO  org.hibernate.cfg.annotations.EntityBinder - Bind entity Livro on table Livro
2944 [main] INFO  org.hibernate.cfg.AnnotationConfiguration - Hibernate Validator not found: ignoring
3035 [main] WARN  org.hibernate.connection.UserSuppliedConnectionProvider - No connection properties specified - the user must supply JDBC connections
3048 [main] INFO  org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
3053 [main] INFO  org.hibernate.transaction.TransactionFactoryFactory - Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
3054 [main] INFO  org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
3054 [main] INFO  org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
3054 [main] INFO  org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
3055 [main] INFO  org.hibernate.cfg.SettingsFactory - Scrollable result sets: disabled
3055 [main] INFO  org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): disabled
3055 [main] INFO  org.hibernate.cfg.SettingsFactory - Connection release mode: auto
3055 [main] INFO  org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2
3056 [main] INFO  org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
3056 [main] INFO  org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
3057 [main] INFO  org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
3057 [main] INFO  org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
3057 [main] INFO  org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
3058 [main] INFO  org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
3059 [main] INFO  org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
3059 [main] INFO  org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: enabled
3059 [main] INFO  org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
3060 [main] INFO  org.hibernate.cfg.SettingsFactory - Query cache: disabled
3060 [main] INFO  org.hibernate.cfg.SettingsFactory - Cache provider: org.hibernate.cache.NoCacheProvider
3060 [main] INFO  org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
3060 [main] INFO  org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
3063 [main] INFO  org.hibernate.cfg.SettingsFactory - Statistics: disabled
3063 [main] INFO  org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
3064 [main] INFO  org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
3064 [main] INFO  org.hibernate.cfg.SettingsFactory - Named query checking : enabled
3086 [main] INFO  org.hibernate.impl.SessionFactoryImpl - building session factory
3290 [main] INFO  org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
3294 [main] INFO  org.hibernate.tool.hbm2ddl.SchemaExport - Running hbm2ddl schema export
3295 [main] INFO  org.hibernate.tool.hbm2ddl.SchemaExport - exporting generated schema to database
3295 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - schema export unsuccessful
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.SchemaExport.execute(SchemaExport.java:180)
        at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
        at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:311)
        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 GeraTabelas.main(GeraTabelas.java:16)
3297 [main] INFO  org.hibernate.impl.SessionFactoryImpl - closing

quanto aos jars, eu acho que tenho todos importados já

Pode postar os métodos do seu JPA? Algo como JPAUtils…

Apenas para certificar 100% de que seu .xml persistence.xml está ok copie e cole com o meu:

[code]<?xml version="1.0" encoding="UTF-8"?>

<persistence-unit name="livraria" transaction-type="RESOURCE_LOCAL">
	<provider>org.hibernate.ejb.HibernatePersistence</provider>
	<properties>
		<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
		<property name="hibernate.hbm2ddl.auto" value="update"/>
		<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
		<property name="javax.persistence.jdbc.user" value="root"/>
		<property name="javax.persistence.jdbc.password" value="root"/>
		<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/livraria"/>
	</properties>
</persistence-unit>

[/code]

Eai, obteve sucesso?

mesma coisa andre

0 [main] INFO  org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.3.1.GA
16 [main] INFO  org.hibernate.cfg.Environment - Hibernate 3.2.5
20 [main] INFO  org.hibernate.cfg.Environment - hibernate.properties not found
23 [main] INFO  org.hibernate.cfg.Environment - Bytecode provider name : cglib
29 [main] INFO  org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
114 [main] INFO  org.hibernate.ejb.Version - Hibernate EntityManager 3.3.2.GA
402 [main] INFO  org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: Editora
443 [main] INFO  org.hibernate.cfg.annotations.EntityBinder - Bind entity Editora on table Editora
486 [main] INFO  org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: Livro
487 [main] INFO  org.hibernate.cfg.annotations.EntityBinder - Bind entity Livro on table Livro
492 [main] INFO  org.hibernate.cfg.AnnotationConfiguration - Hibernate Validator not found: ignoring
567 [main] WARN  org.hibernate.connection.UserSuppliedConnectionProvider - No connection properties specified - the user must supply JDBC connections
583 [main] INFO  org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
587 [main] INFO  org.hibernate.transaction.TransactionFactoryFactory - Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
590 [main] INFO  org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
592 [main] INFO  org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
596 [main] INFO  org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
597 [main] INFO  org.hibernate.cfg.SettingsFactory - Scrollable result sets: disabled
598 [main] INFO  org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): disabled
598 [main] INFO  org.hibernate.cfg.SettingsFactory - Connection release mode: auto
600 [main] INFO  org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2
601 [main] INFO  org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
601 [main] INFO  org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
602 [main] INFO  org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
603 [main] INFO  org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
603 [main] INFO  org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
607 [main] INFO  org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
609 [main] INFO  org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
609 [main] INFO  org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: enabled
610 [main] INFO  org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
611 [main] INFO  org.hibernate.cfg.SettingsFactory - Query cache: disabled
612 [main] INFO  org.hibernate.cfg.SettingsFactory - Cache provider: org.hibernate.cache.NoCacheProvider
613 [main] INFO  org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
613 [main] INFO  org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
619 [main] INFO  org.hibernate.cfg.SettingsFactory - Statistics: disabled
620 [main] INFO  org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
621 [main] INFO  org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
622 [main] INFO  org.hibernate.cfg.SettingsFactory - Named query checking : enabled
734 [main] INFO  org.hibernate.impl.SessionFactoryImpl - building session factory
936 [main] INFO  org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
938 [main] INFO  org.hibernate.tool.hbm2ddl.SchemaUpdate - Running hbm2ddl schema update
938 [main] INFO  org.hibernate.tool.hbm2ddl.SchemaUpdate - fetching database metadata
939 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - 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 GeraTabelas.main(GeraTabelas.java:16)
941 [main] INFO  org.hibernate.impl.SessionFactoryImpl - closing

como eu disse, os códigos q eu criei são aqueles do 1 post, não alterei nada, o netbeans importou as classes do hibernate + jpa e jsf 2, a unica coisa que eu fiz, foi importar o log4j, que eu baixei do site oficial lá

me ajuda a configurar o hibernate + jpa plz?
quais são os jars q eu tenho que importar?
acabei de fazer download do distribution 3.6 do hibernate e vou usar o eclipse.
Como não sei configurar manualmente vai ser de grande ajuda aprender isso também.
E se souberem como configurar o JSF2 eu tb aceito a ajuda :smiley:

Olá André,

Na linha 12 da saída do console que você postou há o seguinte WARNING:

Este erro normalmente acontece quando você erra os nomes das propriedades JDBC. Os nomes corretos são:

javax.persistence.jdbc.user
javax.persistence.jdbc.password
javax.persistence.jdbc.url

Certifique-se que não há espaço ou erro de digitação.

Olá à todos,
Estou com um problema semelhante numa aplicação JSF + Hiberante. Segue log:

WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
java.lang.UnsupportedOperationException: The user must supply a JDBC connection
Listening for transport dt_socket at address: 6223
        at org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:30)
        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:417)
        at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
        at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:118)
        at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
        at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1293)
        at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:37)
        at br.com.hulkmarciano.bodywebclient.filtro.JPAFilter.doFilter(JPAFilter.java:36)                                   //<<<< Aqui ele informa que pode ser um filtro que criei.
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
        at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
        at java.lang.Thread.run(Thread.java:619)

Segue o filtro:

@WebFilter(servletNames = {"Faces Servlet"})
public class JPAFilter implements Filter {

    private EntityManagerFactory factory;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        this.factory = Persistence.createEntityManagerFactory("bodyWebPU");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        EntityManager entityManager = this.factory.createEntityManager();
        request.setAttribute("entityManager", entityManager);
        entityManager.getTransaction().begin();                         /// Segundo o Netbeans o erro é aqui

        chain.doFilter(request, response);
        try {
            entityManager.getTransaction().commit();
        } catch (Exception e) {
            entityManager.getTransaction().rollback();
        } finally {
            entityManager.close();
        }
    }

    @Override
    public void destroy() {
        this.factory.close();
    }
}

Por que não posso utilizar o entityManager.getTransaction().begin(); ? Em geral não utilizo o EntityManagerFactory para pegar a transaction e dar begin, mas estou usando um tuto que peguei e queria usar. Sei que se usasse EJB não precisava do transaction, talvez nem aqui, mas se não utilizar como controlo os comits e os rollback?

Ao remover as “getTransaction()” o “bicho roda”, mas sempre que tenta acessar a base da um erro com a mesma assinatura java.lang.UnsupportedOperationException: The user must supply a JDBC connection. Já troquei o driver do mysql e nada.

Para resolver tive que retirar as tag bugadas do persistence e utilizar as do hibernate:

O que era assim:

<persistence 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"
version="1.0">
<persistence-unit name="copadomundo" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/copadomundo" />
</properties>
</persistence-unit>
</persistence>

Para

<?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="copadomundo" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" />
            <property name="hibernate.connection.show_sql" value="true" />
            <property name="hibernate.hbm2ddl.auto" value="update" />
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver " />
            <property name="hibernate.connection.username" value="root" />
            <property name="hibernate.connection.password" value="root" />
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/copadomundo" />
        </properties>
    </persistence-unit>
</persistence>

E funcionou!

Isto me ajudou muito!
Estava com o mesmo problema e resolvi da mesma forma, obrigado colega ! :smiley:

Estava com o mesmo problema e, com esta alteração no persistence.xml, consegui resolver :smiley:
Muito obrigada!

Eu estava recebendo o mesmo erro, enquanto procura isso no google eu tenho essa página / forum, mas eu não sei Português, então eu usei tradutor do google e encontrei a solução.
pena de erros de digitação.
obrigado.

Estava com o mesmo problema e, com esta alteração no persistence.xml, consegui resolver
Muito obrigado!

Valeu Hulkmarciano!

Alguém poderia me explicar porque assim funciona?

Tenho um projeto web (jboss + jsf) e só funcionou utilizando a api hibernate.connection.
Tenho um outro projeto Java (desktop) e funcionou com a api javax.persistence.jdbc.

Por que isto acontece?

Obrigado.

[quote=Hulkmarciano]Para resolver tive que retirar as tag bugadas do persistence e utilizar as do hibernate:

O que era assim:

<persistence 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"
version="1.0">
<persistence-unit name="copadomundo" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/copadomundo" />
</properties>
</persistence-unit>
</persistence>

Para

<?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="copadomundo" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" />
            <property name="hibernate.connection.show_sql" value="true" />
            <property name="hibernate.hbm2ddl.auto" value="update" />
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver " />
            <property name="hibernate.connection.username" value="root" />
            <property name="hibernate.connection.password" value="root" />
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/copadomundo" />
        </properties>
    </persistence-unit>
</persistence>

E funcionou![/quote]