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

erro ao rodar meu projeto.

exception

javax.servlet.ServletException javax.faces.webapp.FacesServlet.service(FacesServlet.java:659) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) root cause

java.lang.ExceptionInInitializerError br.com.caelum.livraria.dao.DAO.listaTodos(DAO.java:55) br.com.caelum.livraria.bean.LivroBean.getAutores(LivroBean.java:27) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) java.lang.reflect.Method.invoke(Unknown Source) javax.el.BeanELResolver.getValue(BeanELResolver.java:97) com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) org.apache.el.parser.AstValue.getValue(AstValue.java:169) org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184) com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109) javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182) javax.faces.component.UISelectItems.getValue(UISelectItems.java:129) com.sun.faces.renderkit.SelectItemsIterator.initializeItems(SelectItemsIterator.java:208) com.sun.faces.renderkit.SelectItemsIterator.hasNext(SelectItemsIterator.java:135) com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(MenuRenderer.java:762) com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:847) com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:297) javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312) com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185) com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129) javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889) javax.faces.component.UIComponent.encodeAll(UIComponent.java:1896) javax.faces.render.Renderer.encodeChildren(Renderer.java:176) javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889) javax.faces.component.UIComponent.encodeAll(UIComponent.java:1896) javax.faces.component.UIComponent.encodeAll(UIComponent.java:1899) javax.faces.component.UIComponent.encodeAll(UIComponent.java:1899) com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:451) com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131) com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) root cause

javax.persistence.PersistenceException: No Persistence provider for EntityManager named livraria javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61) javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39) br.com.caelum.livraria.dao.JPAUtil.(JPAUtil.java:10) br.com.caelum.livraria.dao.DAO.listaTodos(DAO.java:55) br.com.caelum.livraria.bean.LivroBean.getAutores(LivroBean.java:27) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) java.lang.reflect.Method.invoke(Unknown Source) javax.el.BeanELResolver.getValue(BeanELResolver.java:97) com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) org.apache.el.parser.AstValue.getValue(AstValue.java:169) org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184) com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109) javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182) javax.faces.component.UISelectItems.getValue(UISelectItems.java:129) com.sun.faces.renderkit.SelectItemsIterator.initializeItems(SelectItemsIterator.java:208) com.sun.faces.renderkit.SelectItemsIterator.hasNext(SelectItemsIterator.java:135) com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(MenuRenderer.java:762) com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:847) com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:297) javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312) com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185) com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129) javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889) javax.faces.component.UIComponent.encodeAll(UIComponent.java:1896) javax.faces.render.Renderer.encodeChildren(Renderer.java:176) javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889) javax.faces.component.UIComponent.encodeAll(UIComponent.java:1896) javax.faces.component.UIComponent.encodeAll(UIComponent.java:1899) javax.faces.component.UIComponent.encodeAll(UIComponent.java:1899) com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:451) com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131) com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

11 respostas

Oi Dayson,

tem como colocar o seu persistence.xml?

Deve estar na pasta src/META-INF

abs

solução!
<?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.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/livrariadb" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="root" />

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

</persistence>
('
    <?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.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/livrariadb" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="root" />

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

</persistence>
')

Não estou conseguindo colocar o código completo como fazer?

Oi Dayson, vc precisa usar 3 backsticks (```) no inicio e fim para formatar o seu código, mas eu já arrumei.

O persistence.xml está correto. Ele está na pasta src/META-INF?

abs

sim, coloquei ele dentro do src/main/java do maven, vou criar um projeto Dynamic Web Project de acordo com o curso.

Boa tarde. Estou com o mesmo problema, como resolveram?

Olá Ronney!

A solução foi resolvida!

Vamos lá!

1º você tem que ter uma pasta META-INF dentro de src 2º dentro de META-INF, você precisa ter um arquivo persistence.xml

Segue meu persistence.xml, aí você só altera as configurações

<?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.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/livrariadb" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="root" />

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

</persistence>

Olá Dayson. Uso as mesmas configurações que você. Com JBOSS. Estou desde às 11 da manhã tentando entender o que houve. Importei o projeto, colei o seu XML e nada.

Segue o erro.

14:56:11,821 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-3) HHH000204: Processing PersistenceUnitInfo [
    name: livraria
    ...]
14:56:11,949 WARN  [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (MSC service thread 1-3) HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
14:56:11,964 INFO  [org.hibernate.dialect.Dialect] (MSC service thread 1-3) HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
14:56:11,964 INFO  [org.hibernate.engine.jdbc.internal.LobCreatorBuilder] (MSC service thread 1-3) HHH000422: Disabling contextual LOB creation as connection was null
14:56:11,980 INFO  [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-3) HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
14:56:11,980 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (MSC service thread 1-3) HHH000397: Using ASTQueryTranslatorFactory
14:56:12,011 INFO  [org.hibernate.validator.util.Version] (MSC service thread 1-3) Hibernate Validator 4.2.0.Final
14:56:12,201 INFO  [org.hibernate.tool.hbm2ddl.SchemaUpdate] (MSC service thread 1-3) HHH000228: Running hbm2ddl schema update
14:56:12,201 INFO  [org.hibernate.tool.hbm2ddl.SchemaUpdate] (MSC service thread 1-3) HHH000102: Fetching database metadata
14:56:12,201 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] (MSC service thread 1-3) 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]

14:56:12,201 WARN  [org.hibernate.internal.SessionFactoryImpl] (MSC service thread 1-3) HHH000008: JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()
14:56:12,249 INFO  [org.apache.catalina.core.StandardContext] (MSC service thread 1-2) The listener "com.sun.faces.config.ConfigureListener" is already configured for this context. The duplicate definition has been ignored.
14:56:12,296 INFORMAÇÕES [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-2) Inicializando Mojarra 2.1.7-jbossorg-1 (20120227-1401) para o contexto '/livraria'
14:56:13,823 INFO  [org.jboss.web] (MSC service thread 1-2) JBAS018210: Registering web context: /livraria
14:56:13,831 INFO  [org.jboss.as] (MSC service thread 1-2) JBAS015951: Admin console listening on http://127.0.0.1:9990
14:56:13,832 INFO  [org.jboss.as] (MSC service thread 1-2) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 12892ms - Started 278 of 355 services (76 services are passive or on-demand)
14:56:14,061 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "livraria.war"

bom, na realidade, estou usando Wildfly OK. ele é o Sucessor do JBoss, caso queria realmente o Jboss existe esse passo:

ou se quiser usar o Wildfly, muda pouca coisa.

OBS: por esse erro, seu persistence.xml pode está diferente do nome do dataSource DataSource jndi-name=java:/livrariaDS Então verifique se está igual OK? porque ele é case-sencitive

1 - seu Persistence.xml ficará 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_2_0.xsd"
    version="2.0">

    <persistence-unit name="livraria">

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

        <jta-data-source>java:/livrariaDS</jta-data-source>

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

        <properties>

            <!-- Configuracoes especificas do Hibernate -->
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
            <property name="hibernate.hbm2ddl.auto" value="update" />
            <property name="hibernate.show_sql" value="true" />

        </properties>
    </persistence-unit>
</persistence>

2 - entra na pasta JBOSS 2.1 - modules/com/mysql/main <- dentro desta pasta mais coloca 2 arquivos: modeule.xml e jar do Mysql 2.2 - depois abre o standlone.xml e procura pelo elemento DataSource.

datasource jndi-name="java:/livrariaDS" pool-name="livrariaDS"
                    enabled="true" use-java-context="true">

                    <connection-url>jdbc:mysql://localhost:3306/livraria</connection-url>
                    <driver>com.mysql</driver>
                    <pool>
                        <min-pool-size>10</min-pool-size>
                        <max-pool-size>100</max-pool-size>
                        <prefill>true</prefill>
                    </pool>
                    <security>
                        <user-name>root</user-name>
                        <password>root</password>
                    </security>
                </datasource>
<drivers>

                    <!-- Driver Mysql. -->
                    <driver name="com.mysql" module="com.mysql">
                    <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
                    </driver>
</drivers>

Lembrando que seu persistence.xml tem que ficar dentro de src/META-INF/persistence.xml

Bom dia. Arrumei o persistence.xml. Criei as pastas dentro do diretório do JBOSS, estou usando a versão 7.1.1.Final. Coloquei o Module.XML lá. O conector do MySQL que estou usando é o 5.1.22, também está nessa nova pasta. Configurei standalone.XML. Tá ai o erro eu tinha esquecido de fazer o DataSource.

Ai mudou o erro

09:02:58,919 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014775:    New missing/unsatisfied dependencies:
      service jboss.naming.context.java.livrariaDS (missing) dependents: [service jboss.persistenceunit."livraria.war#livraria"] 

09:02:58,919 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"livraria.war#livraria\"jboss.naming.context.java.livrariaDSMissing[jboss.persistenceunit.\"livraria.war#livraria\"jboss.naming.context.java.livrariaDS]"]}}}