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

Criação de tabelas pelo Hibernate

Boa noite, estou com uma dúvida, tenho um projeto JEE que estou configurando, e percebo que a criação das tabelas não está sendo feito pelo hibernate, segue meu persistence.xml:

<?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="database" transaction-type="RESOURCE_LOCAL">

        <!-- provedor/implementacao do JPA -->
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

        <!-- entidade mapeada -->
        <class>br.com.models.Pessoa</class>

        <properties>
            <!-- dados da conexao -->
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/jeeblank" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="1234" />

            <!--  propriedades do hibernate -->

            <property name="hibernate.hbm2ddl.auto" value="create"/>
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>

        </properties>
    </persistence-unit>

</persistence>

Eu injeto o EntityManager dessa forma:

    @PersistenceContext
    private EntityManager entityManager;

Ao rodar a aplicação, até aparece no console do JBOSS a query para a criação da tabela, porém, ele não cria nada, e o que eu achei estranho é que eu deletei o banco de dados e mesmo assim a query aparece no console do jboss, e a única dependência que eu coloquei do hibernate foi: compileOnly 'org.hibernate:hibernate-core:5.2.5.Final', utilizei apenas essa dependência, pois no próprio site do maven, ele diz que as versões mais novas já tem a entity manager por isso ela já está inclusa no core, será que alguém poderia me explicar onde estou errando?

2 respostas

Olhando o persistence não vi nada de errado.. não tem um log indicando se deu erro na criação na tabela?

solução!

Essa é a parte que seria relevante, no final, a mensagem "Salvando pessoa" eu coloquei pra indicar que está chegando no backend:

Connected to server
[2017-02-03 11:08:28,872] Artifact Gradle : br.com.jee : jee-blank-1.0-SNAPSHOT.war: Artifact is being deployed, please wait...
23:08:28,974 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-8) WFLYSRV0027: Starting deployment of "jee-blank-1.0-SNAPSHOT.war" (runtime-name: "jee-blank-1.0-SNAPSHOT.war")
23:08:29,421 INFO  [org.jboss.as.jpa] (MSC service thread 1-6) WFLYJPA0002: Read persistence.xml for livraria
23:08:29,499 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 3) WFLYJPA0010: Starting Persistence Unit (phase 1 of 2) Service 'jee-blank-1.0-SNAPSHOT.war#livraria'
23:08:29,522 INFO  [org.hibernate.jpa.internal.util.LogHelper] (ServerService Thread Pool -- 3) HHH000204: Processing PersistenceUnitInfo [
    name: livraria
    ...]
23:08:29,529 INFO  [org.jboss.weld.deployer] (MSC service thread 1-6) WFLYWELD0003: Processing weld deployment jee-blank-1.0-SNAPSHOT.war
23:08:29,581 INFO  [org.hibernate.Version] (ServerService Thread Pool -- 3) HHH000412: Hibernate Core {5.0.10.Final}
23:08:29,582 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 3) HHH000206: hibernate.properties not found
23:08:29,583 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 3) HHH000021: Bytecode provider name : javassist
23:08:29,585 INFO  [org.hibernate.validator.internal.util.Version] (MSC service thread 1-6) HV000001: Hibernate Validator 5.2.4.Final
23:08:29,611 INFO  [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 3) HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
23:08:29,743 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-6) WFLYJCA0005: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
23:08:29,770 INFO  [org.jboss.weld.Version] (MSC service thread 1-6) WELD-000900: 2.3.5 (Final)
23:08:29,794 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-5) WFLYJCA0018: Started Driver service with driver-name = jee-blank-1.0-SNAPSHOT.war_com.mysql.jdbc.Driver_5_1
23:08:29,907 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 3) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'jee-blank-1.0-SNAPSHOT.war#livraria'
23:08:30,103 INFO  [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 3) HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
23:08:30,135 INFO  [org.hibernate.envers.boot.internal.EnversServiceImpl] (ServerService Thread Pool -- 3) Envers integration enabled? : true
23:08:30,487 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 3) HHH000227: Running hbm2ddl schema export
23:08:30,493 INFO  [stdout] (ServerService Thread Pool -- 3) Hibernate: drop table if exists Pessoa
23:08:30,493 INFO  [stdout] (ServerService Thread Pool -- 3) Hibernate: create table Pessoa (id integer not null auto_increment, nome varchar(255), primary key (id)) ENGINE=InnoDB
23:08:30,497 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 3) HHH000230: Schema export complete
23:08:31,164 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 20) Inicializando Mojarra 2.2.13.SP1 20160303-1204 para o contexto '/jee'
23:08:31,565 WARNING [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 20) Config document file:/C:/Users/fellipe/Downloads/wildfly-10.1.0.Final/standalone/tmp/vfs/temp/temp1d9a0585162f208f/jee-blank-1.0-SNAPSHOT.war-da2084b501116420/WEB-INF/jboss-web.xml with namespace URI null is not a faces-config or facelet-taglib file.  Ignoring.
23:08:31,916 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 20) WFLYUT0021: Registered web context: /jee
23:08:31,940 INFO  [org.jboss.as.server] (management-handler-thread - 2) WFLYSRV0010: Deployed "jee-blank-1.0-SNAPSHOT.war" (runtime-name : "jee-blank-1.0-SNAPSHOT.war")
[2017-02-03 11:08:31,950] Artifact Gradle : br.com.jee : jee-blank-1.0-SNAPSHOT.war: Artifact is deployed successfully
[2017-02-03 11:08:31,950] Artifact Gradle : br.com.jee : jee-blank-1.0-SNAPSHOT.war: Deploy took 3.079 milliseconds
23:09:41,896 INFO  [stdout] (default task-4) Salvando pessoa...

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software