Jpa with Hibernate implementation does not generate postgresql tables

Asked

Viewed 1,508 times

2

Good evening to all I am using Jpa with the implementation Hibernate to among other features generate tables, the problem is that from one hour to another the tables stopped being generated, someone has already gone through it

follows my persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
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">
<persistence-unit name="comunicaVisual"
    transaction-type="RESOURCE_LOCAL">
    <!-- meu provider é o hibernate -->
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <!-- mapeamento das entidades criadas -->
    <class>br.com.drem.entity.Pessoa</class>
    <class>br.com.drem.entity.Cidade</class>
    <class>br.com.drem.entity.Estado</class>
    <class>br.com.drem.entity.Pais</class>
    <class>br.com.drem.entity.PessoaFisica</class>
    <class>br.com.drem.entity.PessoaJuridica</class>
    <class>br.com.drem.entity.Usuario</class>
    <class>br.com.drem.entity.Funcionario</class>
    <class>br.com.drem.entity.Venda</class>
    <class>br.com.drem.entity.Produto</class>
    <class>br.com.drem.entity.Contato</class>

    <!-- se determinada entidade não estiver participando da query ela vai ser excluida do trabalho -->
    <exclude-unlisted-classes>true</exclude-unlisted-classes> 

    <properties>
        <!-- postgres é o nome da minha database -->
        <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost/postgres" />

        <!-- drive do postgresql 9 -->
        <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />

        <!-- ususário da base de dados -->
        <property name="javax.persistence.jdbc.user" value="postgres" />

        <!-- Senha -->
        <property name="javax.persistence.jdbc.password" value="1" />

        <!-- nome do schema-->
        <property name="hibernate.default_schema" value="dremcom_drem" />

        <!-- metodo para criacao, atualizacao ou exclusao de tables -->
        <property name="hibernate.hbm2ddl.auto" value="update" />

        <!-- para visualizarmos as querys no console -->
        <property name="hibernate.show_sql" value="true" />

        <!-- para formatamos as querys -->
        <property name="hibernate.format_sql" value="true" />

        <!-- dialeto do banco de dados -->
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />


        <property name="hibernate.cache.use_second_level_cache" value="true"/>

        <!--  -->
        <property name="hibernate.cache.use_query_cache" value="true" />
        <property name="hibernate.cache.region.factory_class"
            value="org.hibernate.cache.ehcache.EhCacheRegionFactory" />

    </properties>
</persistence-unit>

  • The property that sets this is the hibernate.hbm2ddl.auto and in your case is correct. My questions are: No error or exception is generated? Are the bank permissions correct? You can create tables "at hand"?

  • I managed to solve the problem, what I did was the following I went to the bank and reported the tables in the property Hibernate.hbm2ddl.auto I put as create I ran the project again and then I changed the property Hibernate.hbm2ddl.auto to update and it worked, it seems to me that when you leave it in update and make changes in a table Hibernate can not manipulate the tables as they really should be.

  • Did you find a solution? Poste as an answer to help other people.

  • ta ai @bigown follows how I did to get.

1 answer

1


Step 01: Completely delete your schema in your database. Step 02: Make the necessary changes to your connection.

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
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">
<persistence-unit name="comunicaVisual"
    transaction-type="RESOURCE_LOCAL">
    <!-- meu provider é o hibernate -->
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <!-- mapeamento das entidades criadas -->
    <class>br.com.drem.entity.Pessoa</class>
    <class>br.com.drem.entity.Cidade</class>
    <class>br.com.drem.entity.Estado</class>
    <class>br.com.drem.entity.Pais</class>
    <class>br.com.drem.entity.PessoaFisica</class>
    <class>br.com.drem.entity.PessoaJuridica</class>
    <class>br.com.drem.entity.Usuario</class>
    <class>br.com.drem.entity.Funcionario</class>
    <class>br.com.drem.entity.Venda</class>
    <class>br.com.drem.entity.Produto</class>
    <class>br.com.drem.entity.Contato</class>

    <!-- se determinada entidade não estiver participando da query ela vai ser excluida do trabalho -->
    <exclude-unlisted-classes>true</exclude-unlisted-classes> 

    <properties>
        <!-- postgres é o nome da minha database -->
        <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost/postgres" />

        <!-- drive do postgresql 9 -->
        <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />

        <!-- ususário da base de dados -->
        <property name="javax.persistence.jdbc.user" value="postgres" />

        <!-- Senha -->
        <property name="javax.persistence.jdbc.password" value="1" />

        <!-- nome do schema-->
        <property name="hibernate.default_schema" value="drem" />


        <!-- para visualizarmos as querys no console -->
        <property name="hibernate.show_sql" value="true" />

        <!-- para formatamos as querys -->
        <property name="hibernate.format_sql" value="true" />

        <!-- dialeto do banco de dados -->
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />

        <!-- metodo para criacao, atualizacao ou exclusao de tables -->
        <property name="hibernate.hbm2ddl.auto" value="update" />


        <property name="hibernate.cache.use_second_level_cache" value="true"/>

        <!--  -->
        <property name="hibernate.cache.use_query_cache" value="true" />
        <property name="hibernate.cache.region.factory_class"
            value="org.hibernate.cache.ehcache.EhCacheRegionFactory" />

    </properties>
</persistence-unit>

Step 3: create the schema again and then run the project.

Obs: local machine passwords 0o

  • You can accept the answer. Then I see if I can understand and vote.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.