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

Erro ao criar datasource - Aula 16

Prezados, Fazendo o curso agora e estou utilizando "tudo" como solicitado, porém, com as versões atuais (abaixo) das aplicações e estou na parte de criação do banco e deu o primeiro trauma (Aula 16).

Eclipse Java EE IDE for Web Developers = Version: Oxygen.3a Release (4.7.3a)
MYSQL: versão 8
Forge: forge-distribution-3.9.0.Final-offline
WildFly: wildfly-13.0.0.Final
mysql-connector-java-5.1.35.jar

**************
--- arquivo pom.xml ---- inicio ----
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>br.com.casadocodigo</groupId>
  <artifactId>casadocodigo</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>war</packaging>
  <build>
    <finalName>casadocodigo</finalName>
  </build>
  <properties>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.jboss.spec.javax.faces</groupId>
      <artifactId>jboss-jsf-api_2.1_spec</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.enterprise</groupId>
      <artifactId>cdi-api</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.annotation</groupId>
      <artifactId>jsr250-api</artifactId>
      <scope>provided</scope>
    </dependency>
  </dependencies>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.jboss.spec</groupId>
        <artifactId>jboss-javaee-6.0</artifactId>
        <version>3.0.3.Final</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>javax.annotation</groupId>
        <artifactId>jsr250-api</artifactId>
        <version>1.0</version>
        <scope>provided</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>
--- arquivo pom.xml ---- fim ----

**************
--- arquivo module.xml ---- inicio ----
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.mysql">
    <resources>
        <resource-root path="mysql-connector-java-5.1.35.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
    </dependencies>
</module>
--- arquivo module.xml ---- fim ----

**************
--- arquivo persistence.xml ---- inicio ----
<?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>
--- arquivo persistence.xml ---- fim ----

**************
ERRO no Console do Eclipse
...: Read persistence.xml for casadocodigo-dev
05:51:47,313 INFO  [org.jboss.weld.deployer] (MSC service thread 1-8) WFLYWELD0003: Processing weld deployment casadocodigo.war
05:51:47,411 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) WFLYCTL0013: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {
    "WFLYCTL0412: Required services that are not installed:" => ["jboss.naming.context.java.jboss.datasources.casadocodigoDS"],
    "WFLYCTL0180: Services with missing/unavailable dependencies" => [
        "jboss.persistenceunit.\"casadocodigo.war#casadocodigo-dev\" is missing [jboss.naming.context.java.jboss.datasources.casadocodigoDS]",
        "jboss.persistenceunit.\"casadocodigo.war#casadocodigo-dev\".__FIRST_PHASE__ is missing [jboss.naming.context.java.jboss.datasources.casadocodigoDS]"
    ]
}
05:51:47,443 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0016: Replaced deployment "casadocodigo.war" with deployment "casadocodigo.war"
12 respostas

Oi Luciana, tudo bem ?

Você chegou a criar esse datasource dentro do wildfly ?

Oi Matheus, não, e também não recordo de algum passo para criar lá, eu criei diretamente no MySQL. Tem q criar lá também? Como faz? Obrigada por enquanto.

Você disse que ia usar um datasource nessa linha:

<jta-data-source>java:jboss/datasources/casadocodigoDS</jta-data-source>

Acho que talvez esse vídeo possa te ajudar :

https://cursos.alura.com.br/course/java-ee-webapp/task/18056

Não sei se já fez

Opi,

Então, fiz sim no arquivo "stand-alone-full" está assim:

<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>
                        <password></password>
                    </security>
                </datasource>

<driver name="mysql" module="com.mysql">
                        <datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlDataSource</datasource-class>
                    </driver>

O banco que criei no MySQL é o "casadocodigo_javaee".

Não entendi bem a diferença entre database e datasource.

Meu arquivo "persistence.xml" está:

<jta-data-source>java:jboss/datasources/casadocodigoDS</jta-data-source>

Percebi também que estava usando o jar do mysql errado e estou usando o "atual" ...

Agora estou com outro erro que segue:
18:12:30,044 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 75) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'casadocodigo.war#casadocodigo-dev'
18:12:30,103 WARN  [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (ServerService Thread Pool -- 75) IJ000604: Throwable while attempting to get a new connection: null: javax.resource.ResourceException: IJ031084: Unable to create connection
    at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:345)
    at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:352)
    at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:287)
    at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.createConnectionEventListener(SemaphoreConcurrentLinkedDequeManagedConnectionPool.java:1326)
    at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.getConnection(SemaphoreConcurrentLinkedDequeManagedConnectionPool.java:499)
    at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getSimpleConnection(AbstractPool.java:632)
    at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getConnection(AbstractPool.java:604)
    at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:624)
    at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:430)
    at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:789)
    at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:138)

Pode me ajudar?

Seu banco de dados não tem senha mesmo ?

Se tiver é necessário indicar no datasource

Opi,

Tem senha, só não passei ela aqui, mas está com senha. Outro detalhes da falha que peguei no Elclipse:

Caused by: javax.resource.ResourceException: IJ031089: Failed to load datasource: com.mysql.jdbc.jdbc2.optional.MysqlDataSource

Este caminho do datasource pode ser que seja diferente neste novo jar , veja meu arquivo module abaixo:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.mysql">
    <resources>
        <resource-root path="mysql-connector-java-8.0.11.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
    </dependencies>
</module>

Agora o meu erro é outro conforme abaixo:

Caused by: java.sql.SQLException: The server time zone value 'Hora oficial do Brasil' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

Sabe onde posso configurar isso?

Prezados, Com muita dificuldade fui evoluindo e também com ajuda do tópico: https://cursos.alura.com.br/forum/topico-erro-ao-executar-testaconta-maven-mysql-39547

https://cursos.alura.com.br/forum/topico-erro-ao-carregar-o-servidor-wildfly-10-time-zone-value-62885

Contudo, mesmo persistindo em banco estou com um erro no Console do Eclipse que segue:

... 00:28:54,613 WARN [org.jboss.as.txn] (ServerService Thread Pool -- 68) WFLYTX0013: The node-identifier attribute on the /subsystem=transactions is set to the default value. This is a danger for environments running multiple servers. Please make sure the attribute value is unique. ... 00:29:14,655 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 75) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'casadocodigo.war#casadocodigo-dev' 00:29:14,907 INFO [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-6) ISPN000128: Infinispan version: Infinispan 'Gaina' 9.2.4.Final 00:29:15,012 ERROR [stderr] (ServerService Thread Pool -- 75) Fri Jun 15 00:29:15 BRT 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

00:29:15,531 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 74) WFLYCLINF0002: Started client-mappings cache from ejb container 00:29:15,588 INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 75) HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect 00:29:15,651 INFO [org.hibernate.envers.boot.internal.EnversServiceImpl] (ServerService Thread Pool -- 75) Envers integration enabled? : true 00:29:16,807 INFO [stdout] (ServerService Thread Pool -- 75) Hibernate: 00:29:16,807 INFO [stdout] (ServerService Thread Pool -- 75)00:29:16,807 INFO [stdout] (ServerService Thread Pool -- 75) create table Livro ( 00:29:16,808 INFO [stdout] (ServerService Thread Pool -- 75) id integer not null auto_increment, 00:29:16,808 INFO [stdout] (ServerService Thread Pool -- 75) descricao longtext, 00:29:16,808 INFO [stdout] (ServerService Thread Pool -- 75) numeroPaginas integer, 00:29:16,809 INFO [stdout] (ServerService Thread Pool -- 75) preco decimal(19,2), 00:29:16,809 INFO [stdout] (ServerService Thread Pool -- 75) titulo varchar(255), 00:29:16,809 INFO [stdout] (ServerService Thread Pool -- 75) primary key (id) 00:29:16,810 INFO [stdout] (ServerService Thread Pool -- 75) )

00:29:18,391 WARN [org.jboss.weld.Bootstrap] (MSC service thread 1-2) WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.jberet.creation.BatchBeanProducer is deprecated from CDI 1.1! 00:29:18,414 WARN [org.jboss.weld.Bootstrap] (MSC service thread 1-2) WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.hibernate.validator.internal.cdi.interceptor.ValidationInterceptor is deprecated from CDI 1.1! 00:29:18,468 WARN [org.jboss.weld.Bootstrap] (MSC service thread 1-2) WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class com.sun.faces.flow.FlowDiscoveryCDIHelper is deprecated from CDI 1.1! ... of 658 services (331 services are lazy, passive or on-demand)

Oi Luciana, quanto ao erro do timezone, faz assim: jdbc:mysql://localhost:3306/locadorajdbc:mysql://localhost:3305/locadora?useTimezone=true&serverTimezone=UTC

coloca os parâmetros na url depois do nome da sua database:

**?useTimezone=true&amp;serverTimezone=UTC**

Obrigada Thiago, mas esse problema resolvi com

SET GLOBAL time_zone = '-03:00';

Agora o meu problema é outro que segue abaixo:

00:29:15,012 ERROR [stderr] (ServerService Thread Pool -- 75) Fri Jun 15 00:29:15 BRT 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
solução!

Oi Luciana, a mesma solução: coloca com parâmetro depois do nome do banco: jdbc:mysql://localhost:3306/locadorajdbc:mysql://localhost:3305/locadora?useSSL=false

Oi Thiago. Foi, obrigada.