009:hibernate基础配置
1、对应
2、介绍mysql的图形化客户端
3、hibernate.cfg.xml; hibm2ddl.auto
a)、先建表还是先建类
4、搭建日志环境并配置显示DDL语句
5、搭建Junit环境
6、hibernate.cfg.xml:show_sql
7、hibernate.cfg.xml.format_sql
8、表名和类名不同,表对表名进行配置
a)Annotation:@Table
b)xml:自己查询
9、字段名和属性相同
a)默认为@Basic
b)xml中不用写colomn
10、字段名和属性名不同
a)Annocation:@column
b)xml自己查询
11、不需要psersistence的字段
a)Annotation:@Transient
b)xml不写
12、映射日期与时间类型,指定时间表精度
a)Annotation:@Temporal
b)xml指定type
13、映射枚举类型
a)@Enumerated
b)xml麻烦
14、字段映射的位置(field或者get方法)
a)best practice:保持field和get.set方法的一致。
15、@lib
011:hbm2ddl.auto
在hibernate.cfg.xml中:
<!-- Drop and re-create the database schema on startup -->
<!-- 要不要hibernate 自动生成建表语句 -->
<property name="hbm2ddl.auto">create</property>
hibernate.hbm2ddl.auto
取值validate/update/create/create-drop
对于create如果数据库里没有这张表,它会自动创建
013:搭建log4j日志环境,显示DDL语句
因为slf4j-nop-1.5.8.jar不普遍,换用log4j
1、点击hibernate----右键-----Build path-----configure Build path-----hibernate----Edit-----User Libraries【把slf4j移除】---Add JARs----apache----log4j-1.2.15-----log4j-1.2.15.jar
但slf4j-1.5.8.jar和log4j-1.2.15.jar不能自动对应起来。需要一个转换器(把slf的换口转换成log4j的接口):
(1)、slf4j-1.5.8-----slf4j-log4j12-1.5.8.jar
(2)、hibernate-distribution-3.32GA----project------etc-------log4j.properties【粘贴到src下面】
可以在log4j.properties中,把不需要提示的注释掉:
# log4j.logger.org.hibernate=debug
#log4j.logger.org.hibernate.type=info
只留:log4j.logger.org.hibernate.tool.hbm2ddl=debug