Solucionado (ver solução)
Solucionado
(ver solução)
4
respostas

Não consigo conectar no Banco

Assim comi na parte I do curso eu faço a importação e coloco a minha senha no Persistence.XML. No curso anterior eu consegui popular o banco. Estou usando JBOSS, removi o JAR do Tomcat e coloquei dois do JBOSS (loggin e transaction). Tudo pelo Build Path e vi que os jars apareceram na pasta Lib do Navigator. Erro abaixo

15:35:29,703 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-5) HHH000204: Processing PersistenceUnitInfo [
    name: livraria
    ...]
15:35:29,954 WARN  [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (MSC service thread 1-5) HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
15:35:29,978 INFO  [org.hibernate.dialect.Dialect] (MSC service thread 1-5) HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
15:35:29,984 INFO  [org.hibernate.engine.jdbc.internal.LobCreatorBuilder] (MSC service thread 1-5) HHH000422: Disabling contextual LOB creation as connection was null
15:35:29,991 INFO  [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-5) HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
15:35:29,995 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (MSC service thread 1-5) HHH000397: Using ASTQueryTranslatorFactory
15:35:30,043 INFO  [org.hibernate.validator.util.Version] (MSC service thread 1-5) Hibernate Validator 4.2.0.Final
15:35:30,467 INFO  [org.hibernate.tool.hbm2ddl.SchemaUpdate] (MSC service thread 1-5) HHH000228: Running hbm2ddl schema update
15:35:30,468 INFO  [org.hibernate.tool.hbm2ddl.SchemaUpdate] (MSC service thread 1-5) HHH000102: Fetching database metadata
15:35:30,469 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] (MSC service thread 1-5) HHH000299: Could not complete schema update: java.lang.UnsupportedOperationException: The application must supply JDBC connections
    at org.hibernate.service.jdbc.connections.internal.UserSuppliedConnectionProviderImpl.getConnection(UserSuppliedConnectionProviderImpl.java:62) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
    at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
    at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:194) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
    at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:178) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:457) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
    at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:84) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_80]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_80]
    at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_80]

15:35:30,479 WARN  [org.hibernate.internal.SessionFactoryImpl] (MSC service thread 1-5) HHH000008: JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()
15:35:30,532 INFO  [org.apache.catalina.core.StandardContext] (MSC service thread 1-5) The listener "com.sun.faces.config.ConfigureListener" is already configured for this context. The duplicate definition has been ignored.
15:35:30,597 INFORMAÇÕES [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-5) Inicializando Mojarra 2.1.7-jbossorg-1 (20120227-1401) para o contexto '/livraria'
15:35:32,962 INFO  [org.jboss.web] (MSC service thread 1-5) JBAS018210: Registering web context: /livraria
15:35:32,971 INFO  [org.jboss.as] (MSC service thread 1-2) JBAS015951: Admin console listening on http://127.0.0.1:9990
15:35:32,971 INFO  [org.jboss.as] (MSC service thread 1-2) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 8478ms - Started 282 of 359 services (76 services are passive or on-demand)
15:35:33,134 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "livraria.war"
4 respostas

Oi, para conseguir te ajudar melhor você pode colar o persistence.xml aqui para nós?

Abraços.

desculpe,

<?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_2_0.xsd"
    version="2.0">

    <persistence-unit name="livraria" transaction-type="RESOURCE_LOCAL">

        <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <class>br.com.caelum.livraria.modelo.Usuario</class>
        <class>br.com.caelum.livraria.modelo.Livro</class>
        <class>br.com.caelum.livraria.modelo.Autor</class>

        <properties>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/livrariadb" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="root" />

            <property name="javax.persistence.jdbc.driverclassname" value="com.mysql.jdbc.Driver" />

            <property name="hibernate.hbm2ddl.auto" value="update" />
            <property name="hibernate.show_sql" value="false" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
        </properties>
    </persistence-unit>

</persistence>
solução!

Tenta trocar esse linha

<provider>org.hibernate.ejb.HibernatePersistence</provider>

Por

<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

Bom dia Renan. Retornou esse erro:

08:07:11,165 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC00001: Failed to start service jboss.deployment.unit."livraria.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."livraria.war".INSTALL: Failed to process phase INSTALL of deployment "livraria.war"
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_80]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_80]
    at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_80]
Caused by: javax.persistence.PersistenceException: JBAS011466: PersistenceProvider 'org.hibernate.jpa.HibernatePersistenceProvider' not found
    at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.lookupProvider(PersistenceUnitDeploymentProcessor.java:555)
    at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.deployPersistenceUnit(PersistenceUnitDeploymentProcessor.java:295)
    at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.addPuService(PersistenceUnitDeploymentProcessor.java:258)
    at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.handleWarDeployment(PersistenceUnitDeploymentProcessor.java:194)
    at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.deploy(PersistenceUnitDeploymentProcessor.java:118)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
    ... 5 more