JavaBean规范:
1.属性私有化,提供get/set
2.提供无参构造器
3.基本数据类型建议使用包装类
5.不能用final修饰 -> CGlibdaili
public class Customer {
private Long cust_id;
private String cust_name;
private String cust_source;
private String cust_industry;
private String cust_level;
private String cust_linkman;
private String cust_phone;
private String cust_mobile;
public Long getCust_id() {
return cust_id;
}
public void setCust_id(Long cust_id) {
this.cust_id = cust_id;
}
public String getCust_name() {
return cust_name;
}
public void setCust_name(String cust_name) {
this.cust_name = cust_name;
}
public String getCust_source() {
return cust_source;
}
public void setCust_source(String cust_source) {
this.cust_source = cust_source;
}
public String getCust_industry() {
return cust_industry;
}
public void setCust_industry(String cust_industry) {
this.cust_industry = cust_industry;
}
public String getCust_level() {
return cust_level;
}
public void setCust_level(String cust_level) {
this.cust_level = cust_level;
}
public String getCust_linkman() {
return cust_linkman;
}
public void setCust_linkman(String cust_linkman) {
this.cust_linkman = cust_linkman;
}
public String getCust_phone() {
return cust_phone;
}
public void setCust_phone(String cust_phone) {
this.cust_phone = cust_phone;
}
public String getCust_mobile() {
return cust_mobile;
}
public void setCust_mobile(String cust_mobile) {
this.cust_mobile = cust_mobile;
}
@Override
public String toString() {
return "Customer [cust_id=" + cust_id + ", cust_name=" + cust_name + ", cust_source=" + cust_source
+ ", cust_industry=" + cust_industry + ", cust_level=" + cust_level + ", cust_linkman=" + cust_linkman
+ ", cust_phone=" + cust_phone + ", cust_mobile=" + cust_mobile + "]";
}
public Customer() {
super();
}
}
实体类准备
主键种类:
代理主键:业务无关,对象无关,不能修改
自然主键:表中存在非空并且唯一的字段,例如身份证号
主键生成策略 - 新增数据时,主键生成的方式
代理主键:
identity:数据库维护,自增长,不需要要手动录入
sequence:数据库维护,seq.nextVal序列方式,需要指定参数【序列名】,不需要手动录入
incremen:Hibernate维护,自增长,不需要录入,再插入之前先查找ID最大值,+1插入
hilo:自增长算法
native:hilo + identity + sequence 自动检测
uuid:hibernate维护,id类型设置位varchar(32)
自然主键:必须手动录入
assigned
hibernate对象状态
1.瞬时状态:对象没id,并且没有在session缓存中
2.持久化状态:对象有id,并且在session缓存中,内容发生修改,在事务提交时,都会同步到数据库中
3.游离|托管状态:对象有id,没有不在session缓存中session中对对象的操作,其实就是改变对象的状态
session缓存作用:为了提高查询效率——hibernate一级缓存
session快照:为了节省不必要的update操作
懒加载:load方法懒加载,lazy = "true"(默认)
结论:默认设置就是最佳的优化方案