015:showsql-formatsql
在hibernate.cfg.xml中有:
<!-- Echo all executed SQL to stdout -->
<!-- 把生成的sql语句打印出来 -->
<property name="show_sql">true</property>
还有format_sql也是取两个值true和false
<property name="format_sql">true</property>
作用:会把建表语句加工一下(作用差不多)
016:hibernate基础配置:
对teacher.java:
在对class.Teacher写注解的时候(如果没有指明白,它默认的就是找叫teacher的表,如果数据库的表不叫teacher可以用一个注解指明,叫@table)
而@table不是@table-org.hibernate.anntation
是@table-javax.persistence
@Entity
public class Teacher {
private int id;
private String name;
private String title;
@table(name="_Teacher")
这句语的意思当我映射到Teacher类的时候,它会去找数据库对应的表“_Teacher”,而不再找叫Teacher的表(如果没有会自动生成)
9、字段名和属性相同
a)、默认为@Basic
b)、xml中不用写column
10、字段名和属性名不同
b)、xml自己查
@colmn【是javax.persistence】(name="_name")
@Column
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
这样数据库中表的字段变为“_name”.用这种方法可以指定字段名和数组名不对应的情况
11、不需要psersistence的字段
a)、Annotation:@Transient
b)、xml不写
例如:假定yourwifeName不要有对应的字段存到数据库中去
@Transient
@Transient
public String getYourwifeName() {
return yourwifeName;
}
public void setYourwifeName(String yourwifeName) {
this.yourwifeName = yourwifeName;
}
12、映射日期与时间类型,指定时间精度
a)Anntation:@Temporal
b)xml:指定type
定义Date类型(即包括日期又包括时间)
private Date birthDate;
@Temporal(TemporalType.DATE)
public Date getBirthDate() {
return birthDate;
}
public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
TemporalType.DATE(只记日期)
TemporalType.TimsTamp(记日期和时间)
TemporalType.Time
13、映射枚举类型
a)、@Enumerated
b)、xml
建一个新枚举类型:
com.bjsxt.hibernate.model----右键----new ------Enum【ZhiCheng】
private ZhiCheng zhiCheng;
@Enumerated(EnumType.STRING)
public ZhiCheng getZhiCheng() {
return zhiCheng;
}
public void setZhiCheng(ZhiCheng zhiCheng) {
this.zhiCheng = zhiCheng;
}