奇怪的是hibernate.hbm2ddl.auto行为

时间:2014-03-25 09:00:08

标签: java hibernate jboss persistence.xml

我已经使用 hibernate.hbm2ddl.auto = create 部署了一个应用程序,发现我的许多表都被删除了!我曾经做过同样的事情,但是使用EclipseLink而不是Hibernate,数据库返回表已经存在,这意味着它只会启动create table。 我怀疑如果删除hibernate.hbm2ddl.auto设置为“create”,然后创建表。

任何人都能证实我的怀疑吗? 谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

这是我的hibernate配置文件,它可以正常工作。

<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">org.h2.Driver</property>
        <property name="connection.url">jdbc:h2:tcp://localhost/mem:test:MVCC=true;INIT=create schema IF NOT EXISTS OVT;DB_CLOSE_DELAY=10</property>
        <property name="connection.username">sa</property>
        <property name="connection.password"></property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">100</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.H2Dialect</property>

        <!-- Disable the second-level cache -->
        <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">create</property>

        <mapping class="model.concretes.varlik.Tasit" />
        <mapping class="model.concretes.varlik.Kisi" />
        <mapping class="model._framework.concretes.varlik.Log" />
        <mapping class="model._framework.concretes.varlik.Yetki" />
    </session-factory>
</hibernate-configuration>