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

WFLYWELD0037: Error injecting persistence unit into CDI managed bean.

Não estou conseguindo subir aplicação.

13:15:20,912 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC000001: Failed to start service jboss.deployment.unit."casadocodigo.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."casadocodigo.war".WeldStartService: Failed to start service
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalArgumentException: WFLYWELD0037: Error injecting persistence unit into CDI managed bean. Can't find a persistence unit named '' in deployment casadocodigo.war for injection point private javax.persistence.EntityManager br.com.casadocodigo.loja.daos.LivroDao.manager
    at org.jboss.as.weld.services.bootstrap.WeldJpaInjectionServices.getScopedPUName(WeldJpaInjectionServices.java:114)
    at org.jboss.as.weld.services.bootstrap.WeldJpaInjectionServices.registerPersistenceContextInjectionPoint(WeldJpaInjectionServices.java:77)
4 respostas

Oi Michael, tudo bem?

Veja se o persistence unit no persistence.xml e a unidade de persistencia passada no EntityManagerFactory dentro da classe JPAUtil estão com o mesmo nome.

Não tenho essa classe JPAUtil. Ate o momento no curso não vir ele cometendo isso.

solução!

Desculpe Michael, confundi o curso =) .

Depois de criar o Persistence:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        version="2.1"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
    http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="casadocodigo-dev" transaction-type="JTA">
        <description>Dev persistence unit</description>
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <!-- java transaction api || JNDI -->
        <jta-data-source>java:jboss/datasources/casadocodigoDS</jta-data-source>
        <properties>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
        </properties>
    </persistence-unit>
</persistence>

Precisa configurar o DataSource:

<datasource jndi-name="java:jboss/datasources/casadocodigoDS" pool-name="casadocodigoDS">
                    <connection-url>jdbc:mysql://localhost:3306/casadocodigo_javaee</connection-url>
                    <connection-property name="DatabaseName">
                        casadocodigo_javaee
                    </connection-property>
                    <driver>mysql</driver>
                    <pool>
                        <min-pool-size>10</min-pool-size>
                        <max-pool-size>20</max-pool-size>
                    </pool>
                    <security>
                        <user-name>root</user-name>
                    </security>
                </datasource>
                <drivers>
                    <driver name="mysql" module="com.mysql">
                        <datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlDataSource</datasource-class>
                    </driver>
                </drivers>

não esqueça também do module.xml, do jar de conexão do banco e de criar o banco no mysql tb.

O erro que está dando no seu log é devido a unidade de persistencia estar vindo vazia. Confira o data source e o persistence e veja se todos os passos da configuração foram executados.

Obrigado.

Conseguir solucionar o erro, apaguei o persistence.xml é recriei.

Funcionou.