一 hibernate.cfg.xml常用配置
注意:hibernate的前缀可以省略。
二 测试控制台不输出sql调试信息
三 测试格式化输出sql调试信息
<property name="show_sql">trueproperty>
<property name="format_sql">trueproperty>
控制台输出:
Hibernate:
insert
into
STUDENTS
(SNAME, GENDER, BIRTHDAY, ADDRESS, SID)
values
(?, ?, ?, ?, ?)
四 测试重新创建表结构
<property name="show_sql">trueproperty>
<property name="format_sql">trueproperty>
<property name="hbm2ddl.auto">createproperty>
控制台输出:
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
(?, ?, ?, ?, ?)
五 测试更新表数据
<property name="show_sql">trueproperty>
<property name="format_sql">trueproperty>
<property name="hbm2ddl.auto">updateproperty>
控制台输出:
Hibernate:
insert
into
STUDENTS
(SNAME, GENDER, BIRTHDAY, ADDRESS, SID)
values
(?, ?, ?, ?, ?)
六 default_schema测试
<property name="show_sql">trueproperty>
<property name="format_sql">trueproperty>
<property name="default_schema">hibernateproperty>
<property name="hbm2ddl.auto">createproperty>
控制台输出:
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
(?, ?, ?, ?, ?)