您的位置:首页 > 其它

hiberante.hbm2ddl.auto参数配置

2016-01-27 09:45 204 查看
hibernate.cfg.xml的配置:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>

<!-- Database connection settings -->
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:hsql://localhost</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>

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

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

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</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">update</property>

<mapping resource="org/hibernate/tutorial/domain/Event.hbm.xml"/>

</session-factory>

</hibernate-configuration>

hibernate.hbm2ddl.auto :可以通过hibernate的*.hbm.xml的配置来动态创建数据库的表结构(通过DDL语言)

可配置属性值:create-drop|create|update|validate

create-drop:表示在hebarinate初始化时创建表格,程序运行结束的时候会删除相应的表格

create:在hibernate每次初始化时会都会重新创建表格,在运行结束之后不删除表格

update:只是根据映射文件去验证数据库中的表,如果不一致,就更新表的结构

validate:只是根据映射文件去验证数据库中的表,不一致只是报错而不更新数据库表结构
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: