---
title: "hibernate常用配置"
author: "cakin24"
date: "2017-11-04T06:53:32Z"
tags: []
categories: ["编程语言"]
slug: "hibernate"
draft: false
lastmod: "2017-11-04T06:53:32Z"
id: 2398643
url: "https://cakin24.iteye.com/blog/2398643"
---

一 hibernate.cfg.xml常用配置

![](http://dl2.iteye.com/upload/attachment/0127/6867/2a820417-ce31-3986-b5e5-343f2dadb086.png)  
 

注意：hibernate的前缀可以省略。

 

二 测试控制台不输出sql调试信息

        &lt;!--

        &lt;property name="show\_sql"&gt;true&lt;/property&gt;

        &lt;property name="format\_sql"&gt;true&lt;/property&gt;

        &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;

        --&gt;

 

三 测试格式化输出sql调试信息

        &lt;property name="show\_sql"&gt;true&lt;/property&gt;

        &lt;property name="format\_sql"&gt;true&lt;/property&gt;

        &lt;!--

        &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;

        --&gt;

控制台输出：

Hibernate:

    insert

    into

        STUDENTS

        (SNAME, GENDER, BIRTHDAY, ADDRESS, SID)

    values

        (?, ?, ?, ?, ?)

 

四 测试重新创建表结构

        &lt;property name="show\_sql"&gt;true&lt;/property&gt;

        &lt;property name="format\_sql"&gt;true&lt;/property&gt;

        &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;

控制台输出：

Hibernate:

    drop table if exists STUDENTS

Hibernate:

    create table STUDENTS (

        SID integer not null,

        SNAME varchar(255),

        GENDER varchar(255),

        BIRTHDAY datetime,

        ADDRESS varchar(255),

        primary key (SID)

    )

九月 17, 2017 4:43:20 下午 org.hibernate.tool.hbm2ddl.SchemaExport execute

INFO: HHH000230: Schema export complete

Hibernate:

    insert

    into

        STUDENTS

        (SNAME, GENDER, BIRTHDAY, ADDRESS, SID)

    values

        (?, ?, ?, ?, ?)

 

 

五 测试更新表数据

        &lt;property name="show\_sql"&gt;true&lt;/property&gt;

        &lt;property name="format\_sql"&gt;true&lt;/property&gt;

        &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;

控制台输出：

Hibernate:

    insert

    into

        STUDENTS

        (SNAME, GENDER, BIRTHDAY, ADDRESS, SID)

    values

        (?, ?, ?, ?, ?)

 

六 default\_schema测试

        &lt;property name="show\_sql"&gt;true&lt;/property&gt;

        &lt;property name="format\_sql"&gt;true&lt;/property&gt;

        &lt;property name="default\_schema"&gt;hibernate&lt;/property&gt;

        &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;

控制台输出：

Hibernate:

    drop table if exists hibernate.STUDENTS

Hibernate:

    create table hibernate.STUDENTS (

        SID integer not null,

        SNAME varchar(255),

        GENDER varchar(255),

        BIRTHDAY datetime,

        ADDRESS varchar(255),

        primary key (SID)

    )

九月 17, 2017 4:52:47 下午 org.hibernate.tool.hbm2ddl.SchemaExport execute

INFO: HHH000230: Schema export complete

Hibernate:

    insert

    into

        hibernate.STUDENTS

        (SNAME, GENDER, BIRTHDAY, ADDRESS, SID)

    values

 

        (?, ?, ?, ?, ?)