0

Ao iniciar o wildfly eu esperava que as tabelas fossem criadas no banco porém no console mostra um log de create tables porém nada acontece no banco. Abaixo mostro isso:

    14:15:00,462 INFO  [org.jboss.modules] (main) JBoss Modules version 1.5.1.Final
    14:15:00,880 INFO  [org.jboss.msc] (main) JBoss MSC version 1.2.6.Final
    14:15:00,999 INFO  [org.jboss.as] (MSC service thread 1-7) WFLYSRV0049: WildFly Full 10.0.0.Final (WildFly Core 2.0.10.Final) starting
    14:15:03,023 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) WFLYDS0004: Found pokemax.war in deployment directory. To trigger deployment create a file called pokemax.war.dodeploy
    14:15:03,127 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http)
    14:15:03,171 INFO  [org.xnio] (MSC service thread 1-4) XNIO version 3.3.4.Final
    14:15:03,208 INFO  [org.xnio.nio] (MSC service thread 1-4) XNIO NIO Implementation Version 3.3.4.Final
    14:15:03,333 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 33) WFLYJCA0004: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
    14:15:03,333 INFO  [org.jboss.remoting] (MSC service thread 1-4) JBoss Remoting version 4.0.18.Final
    14:15:03,348 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 38) WFLYCLINF0001: Activating Infinispan subsystem.
    14:15:03,387 INFO  [org.jboss.as.jsf] (ServerService Thread Pool -- 44) WFLYJSF0007: Activated the following JSF Implementations: [main]
    14:15:03,401 INFO  [org.wildfly.extension.io] (ServerService Thread Pool -- 37) WFLYIO001: Worker 'default' has auto-configured to 8 core threads with 64 task threads based on your 4 available processors
    14:15:03,425 INFO  [org.jboss.as.connector] (MSC service thread 1-8) WFLYJCA0009: Starting JCA Subsystem (WildFly/IronJacamar 1.3.2.Final)
    14:15:03,427 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 46) WFLYNAM0001: Activating Naming Subsystem
    14:15:03,460 WARN  [org.jboss.as.txn] (ServerService Thread Pool -- 54) WFLYTX0013: Node identifier property is set to the default value. Please make sure it is unique.
    14:15:03,487 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) WFLYJCA0018: Started Driver service with driver-name = h2
    14:15:03,721 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 53) WFLYSEC0002: Activating Security Subsystem
    14:15:03,722 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 56) WFLYWS0002: Activating WebServices Extension
    14:15:03,749 INFO  [org.jboss.as.security] (MSC service thread 1-4) WFLYSEC0001: Current PicketBox version=4.9.4.Final
    14:15:03,752 INFO  [org.jboss.as.naming] (MSC service thread 1-1) WFLYNAM0003: Starting Naming Service
    14:15:03,753 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-2) WFLYMAIL0001: Bound mail session [java:jboss/mail/Default]
    14:15:03,797 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-7) WFLYUT0003: Undertow 1.3.15.Final starting
    14:15:03,810 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 55) WFLYUT0003: Undertow 1.3.15.Final starting
    14:15:04,221 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 55) WFLYUT0014: Creating file handler for path '/opt/wildfly-10.0.0.Final/welcome-content' with options [directory-listing: 'false', follow-symlink: 'false', case-sensitive: 'true', safe-symlink-paths: '[]']
    14:15:04,285 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-5) WFLYUT0012: Started server default-server.
    14:15:04,324 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-3) WFLYUT0018: Host default-host starting
    14:15:04,344 INFO  [org.jboss.as.ejb3] (MSC service thread 1-2) WFLYEJB0481: Strict pool slsb-strict-max-pool is using a max instance size of 64 (per class), which is derived from thread worker pool sizing.
    14:15:04,347 INFO  [org.jboss.as.ejb3] (MSC service thread 1-1) WFLYEJB0482: Strict pool mdb-strict-max-pool is using a max instance size of 16 (per class), which is derived from the number of CPUs on this host.
    14:15:04,517 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-7) WFLYUT0006: Undertow HTTP listener default listening on 127.0.0.1:8080
    14:15:04,999 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-7) WFLYJCA0001: Bound data source [java:jboss/datasources/ExampleDS]
    14:15:05,197 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-3) WFLYDS0013: Started FileSystemDeploymentService for directory /opt/wildfly-10.0.0.Final/standalone/deployments
    14:15:05,202 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-7) WFLYSRV0027: Starting deployment of "pokemax.war" (runtime-name: "pokemax.war")
    14:15:05,575 INFO  [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-6) ISPN000128: Infinispan version: Infinispan 'Mahou' 8.1.0.Final
    14:15:05,594 INFO  [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-8) ISPN000128: Infinispan version: Infinispan 'Mahou' 8.1.0.Final
    14:15:05,573 INFO  [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-2) ISPN000128: Infinispan version: Infinispan 'Mahou' 8.1.0.Final
    14:15:05,571 INFO  [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-5) ISPN000128: Infinispan version: Infinispan 'Mahou' 8.1.0.Final
    14:15:05,836 INFO  [org.jboss.ws.common.management] (MSC service thread 1-1) JBWS022052: Starting JBossWS 5.1.3.Final (Apache CXF 3.1.4) 
    14:15:09,089 INFO  [org.jboss.as.jpa] (MSC service thread 1-6) WFLYJPA0002: Read persistence.xml for pokemax
    14:15:09,432 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 59) WFLYJPA0010: Starting Persistence Unit (phase 1 of 2) Service 'pokemax.war#pokemax'
    14:15:09,469 INFO  [org.hibernate.jpa.internal.util.LogHelper] (ServerService Thread Pool -- 59) HHH000204: Processing PersistenceUnitInfo [
        name: pokemax
        ...]
    14:15:09,579 INFO  [org.jboss.weld.deployer] (MSC service thread 1-4) WFLYWELD0003: Processing weld deployment pokemax.war
    14:15:09,707 INFO  [org.hibernate.Version] (ServerService Thread Pool -- 59) HHH000412: Hibernate Core {5.0.7.Final}
    14:15:09,712 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 59) HHH000206: hibernate.properties not found
    14:15:09,722 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 59) HHH000021: Bytecode provider name : javassist
    14:15:09,843 INFO  [org.hibernate.orm.deprecation] (ServerService Thread Pool -- 59) HHH90000001: Found usage of deprecated setting for specifying Scanner [hibernate.ejb.resource_scanner]; use [hibernate.archive.scanner] instead
    14:15:09,848 INFO  [org.hibernate.validator.internal.util.Version] (MSC service thread 1-4) HV000001: Hibernate Validator 5.2.3.Final
    14:15:09,877 INFO  [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 59) HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
    14:15:10,512 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-8) WFLYJCA0005: Deploying non-JDBC-compliant driver class com.mysql.cj.jdbc.Driver (version 6.0)
    14:15:10,514 INFO  [org.jboss.weld.deployer] (MSC service thread 1-8) WFLYWELD0006: Starting Services for CDI deployment: pokemax.war
    14:15:10,554 INFO  [org.jboss.weld.Version] (MSC service thread 1-8) WELD-000900: 2.3.2 (Final)
    14:15:10,612 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-5) WFLYJCA0018: Started Driver service with driver-name = pokemax.war_com.mysql.cj.jdbc.Driver_6_0
    14:15:10,613 INFO  [org.jboss.weld.deployer] (MSC service thread 1-7) WFLYWELD0009: Starting weld service for deployment pokemax.war
    14:15:10,922 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 59) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'pokemax.war#pokemax'
    14:15:11,235 INFO  [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 59) HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
    14:15:11,297 INFO  [org.hibernate.envers.boot.internal.EnversServiceImpl] (ServerService Thread Pool -- 59) Envers integration enabled? : true
    14:15:12,082 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 59) HHH000227: Running hbm2ddl schema export
    14:15:12,091 INFO  [stdout] (ServerService Thread Pool -- 59) Hibernate: 
    14:15:12,092 INFO  [stdout] (ServerService Thread Pool -- 59)     drop table if exists tb_habilidade
    14:15:12,093 INFO  [stdout] (ServerService Thread Pool -- 59) Hibernate: 
    14:15:12,094 INFO  [stdout] (ServerService Thread Pool -- 59)     drop table if exists tb_pokemon
    14:15:12,095 INFO  [stdout] (ServerService Thread Pool -- 59) Hibernate: 
    14:15:12,095 INFO  [stdout] (ServerService Thread Pool -- 59)     create table tb_habilidade (
    14:15:12,095 INFO  [stdout] (ServerService Thread Pool -- 59)         id bigint not null auto_increment,
    14:15:12,096 INFO  [stdout] (ServerService Thread Pool -- 59)         descricao varchar(150) not null,
    14:15:12,096 INFO  [stdout] (ServerService Thread Pool -- 59)         efeito_secundario varchar(255),
    14:15:12,096 INFO  [stdout] (ServerService Thread Pool -- 59)         nome varchar(20) not null,
    14:15:12,097 INFO  [stdout] (ServerService Thread Pool -- 59)         primary key (id)
    14:15:12,097 INFO  [stdout] (ServerService Thread Pool -- 59)     ) ENGINE=InnoDB
    14:15:12,108 INFO  [stdout] (ServerService Thread Pool -- 59) Hibernate: 
    14:15:12,108 INFO  [stdout] (ServerService Thread Pool -- 59)     create table tb_pokemon (
    14:15:12,108 INFO  [stdout] (ServerService Thread Pool -- 59)         id bigint not null auto_increment,
    14:15:12,108 INFO  [stdout] (ServerService Thread Pool -- 59)         ataque bigint not null,
    14:15:12,109 INFO  [stdout] (ServerService Thread Pool -- 59)         ataque_especial bigint not null,
    14:15:12,109 INFO  [stdout] (ServerService Thread Pool -- 59)         defesa bigint not null,
    14:15:12,109 INFO  [stdout] (ServerService Thread Pool -- 59)         defesa_especial bigint not null,
    14:15:12,109 INFO  [stdout] (ServerService Thread Pool -- 59)         descricao varchar(150) not null,
    14:15:12,109 INFO  [stdout] (ServerService Thread Pool -- 59)         hp bigint not null,
    14:15:12,110 INFO  [stdout] (ServerService Thread Pool -- 59)         nome varchar(20) not null,
    14:15:12,110 INFO  [stdout] (ServerService Thread Pool -- 59)         numeroDex bigint not null,
    14:15:12,110 INFO  [stdout] (ServerService Thread Pool -- 59)         tipoDois varchar(20),
    14:15:12,110 INFO  [stdout] (ServerService Thread Pool -- 59)         tipoUm varchar(20) not null,
    14:15:12,110 INFO  [stdout] (ServerService Thread Pool -- 59)         velocidade bigint not null,
    14:15:12,111 INFO  [stdout] (ServerService Thread Pool -- 59)         primary key (id)
    14:15:12,111 INFO  [stdout] (ServerService Thread Pool -- 59)     ) ENGINE=InnoDB
    14:15:12,113 INFO  [stdout] (ServerService Thread Pool -- 59) Hibernate: 
    14:15:12,113 INFO  [stdout] (ServerService Thread Pool -- 59)     alter table tb_pokemon 
    14:15:12,114 INFO  [stdout] (ServerService Thread Pool -- 59)         add constraint UKa1g6imng0eltmqxv6v110t0go unique (nome, numeroDex)
    14:15:12,115 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 59) HHH000230: Schema export complete
    14:15:13,520 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 58) Inicializando Mojarra 2.2.12-jbossorg-2 20150729-1131 para o contexto '/pokemax'
    14:15:15,948 INFO  [org.primefaces.webapp.PostConstructApplicationEventListener] (ServerService Thread Pool -- 58) Running on PrimeFaces 5.3
    14:15:15,980 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 58) WFLYUT0021: Registered web context: /pokemax
    14:15:16,053 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "pokemax.war" (runtime-name : "pokemax.war")
    14:15:16,271 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
    14:15:16,273 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
    14:15:16,273 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 10.0.0.Final (WildFly Core 2.0.10.Final) started in 16424ms - Started 368 of 657 services (382 services are lazy, passive or on-demand)

O meu arquivo persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
    xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="pokemax" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost/pokemax" />
            <property name="hibernate.connection.driver" value="com.mysql.jdbc.Driver" />
            <property name="hibernate.connection.username" value="pokemax" />
            <property name="hibernate.connection.password" value="pokemax2" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true" />
            <property name="hibernate.hbm2ddl.auto" value="create-drop" />
        </properties>
    </persistence-unit>
</persistence>

E minha classe Util:

package br.com.pokemax.util;

import java.util.logging.Logger;

import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

public class HibernateUtil {

    @Produces
    @PersistenceContext
    private EntityManager em;

    @Produces
    public Logger produceLog(InjectionPoint injectionPoint) {
        return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
    }

}

Eu inclusive coloquei uma senha errada para ver se está abrindo conexão mas pelo visto não porque não vejo nenhum erro referente.

Alguém pode ajudar a resolver este problema?

1 Resposta 1

1

Repare que no seu arquivo persistence.xml tem a linha:

<property name="hibernate.hbm2ddl.auto" value="create-drop" />

Com o valor create-drop o hibernate vai apagar todas as tabelas, criar tabelas novas e no fim da sessão apagar todas as tabelas de novo. Mude para create ou update, que as tabelas continuaram no banco de dados mesmo depois da aplicação terminar.

Por exemplo:

<property name="hibernate.hbm2ddl.auto" value="create" />

Com o valor create o hibernate vai apagar todas as tabelas no início e criar tabelas novas, apagando todos os seus dados que estavam no banco antes da aplicação começar. Se você quiser que os dados não sejam apagados use update.

Talvez seja isso, se não for comente aqui na resposta por favor!

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .