jpa抓取战略详解fetch(lazy ,eager)[Java编程]
本文“jpa抓取战略详解fetch(lazy ,eager)[Java编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
在jpa中jpa默许的加载方法是lazy方法也就是在实际利用到数据的时刻才加 载相关数据,利用lazy时可以不用显示注明fetch=FetchType.LAZY
实体bean:carage
Java代码
package com.hibernate.jpa.bean1;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
@Entity
public class Garage {
/**
* many to one 多对一
*/
private Integer gid;
private String garagenum;
private Set<Auto> autos = new HashSet<Auto> ();
@Id @GeneratedValue
public Integer getGid() {
return gid;
}
public void setGid(Integer gid) {
this.gid = gid;
}
@Column(length=20)
public String getGaragenum() {
return garagenum;
}
public void setGaragenum(String garagenum) {
this.garagenum = garagenum;
}
@OneToMany(cascade={CascadeType.PERSIST},mappedBy="garage")
public Set<Auto> getAutos() {
return autos;
}
public void setAutos(Set<Auto> autos) {
this.autos = autos;
}
public void addGarageAuto(Auto auto) {
auto.setGarage(this);
this.autos.add(auto);
}
}
以上是“jpa抓取战略详解fetch(lazy ,eager)[Java编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |