---
title: "关于Hibernate一个配置参数hibernate.hbm2ddl.auto"
author: "java_lk"
date: "2008-08-20T11:13:19Z"
tags: []
slug: "hibernate-hibernate-hbm2ddl-auto"
draft: false
lastmod: "2008-08-20T11:13:19Z"
id: 230493
url: "https://java-lk.iteye.com/blog/230493"
---

做东西时用到了该参数，查找并摘录自：http://blog.csdn.net/MyJSF/archive/2007/11/11/1879467.aspx

【摘录内容】
<properties>
           <property name="hibernate.show_sql" value="true" />      
           <property name="hibernate.hbm2ddl.auto" value="create" />
</properties>

Hibernate的参数配置，解释如下：

hibernate.hbm2ddl.auto Automatically validate or export schema DDL to the database when the SessionFactory is created. With create-drop, the database schema will be dropped when the SessionFactory is closed explicitly.  eg. validate | update | create | create-drop

其实这个参数的作用主要用于：自动创建|更新|验证数据库表结构。如果不是此方面的需求建议set value="none".

其它几个参数的意思，我解释一下：

 validate               加载hibernate时，验证创建数据库表结构
 create                  每次加载hibernate，重新创建数据库表结构，这就是导致数据库表数据丢失的原因。
 create-drop        加载hibernate时创建，退出是删除表结构
 update                 加载hibernate自动更新数据库结构

总结：

1.请慎重使用此参数，没必要就不要随便用。

2.如果发现数据库表丢失，请检查hibernate.hbm2ddl.auto的配置