Why are tables created in Hibernate deleted after stopping the server?

Asked

Viewed 184 times

1

I run my website and it generates the tables in the database. I can even register in the database by the site and its der a select it shows that it was registered. But if I stop the server, and see the tables in Mysql, the table is gone.

The persistence is like this:

<?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="nome">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>br.com.nome.model.Tabela</class>
        <properties>
            <property name="javax.persistence.jdbc.driver"
            value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url"
            value="jdbc:mysql://localhost/bd" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="senha" />
            <property name="hibernate.dialect"
            value="org.hibernate.dialect.MySQL5InnoDBDialect" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true" />
            <property name="hibernate.hbm2ddl.auto" value="update" />
        </properties>
    </persistence-unit>
</persistence>

1 answer

1

Apparently the configuration file is correct, you should delete when the property hbm2ddl were it so:

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

Maybe it’s some database configuration or your application server.
Or you can change the attribute to :

property name="hibernate.hbm2ddl.auto" value="create"
  • happens when I stop the server

  • It was configured create-drop in the spring mvc configuration, I switched there and it worked, thanks.

Browser other questions tagged

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