使用session.merge时Hibernate中的性能问题

时间:2014-12-16 08:48:11

标签: java performance hibernate

我有一个方法:

// method
Session session = Context.getHibernateSession();
Transaction tx = session.beginTransaction();
private void method(TableAList AList) {
for(A a : AList) {
session.merge(a);
}
tx.commit();
}

当AList包含超过40到50个表A的对象时,它变得非常慢并且需要很长时间才能完成。如何解决这个问题?

实体A:

/**
 * The persistent class for the A database table.
 * 
 */
@Entity
@Table(name="A")
public class A implements Serializable {
private static final long serialVersionUID = 1L;

@EmbeddedId
private APK id;

@Column(name="ACTION_CD")
private String actionCd;

@Column(name="AD_LMT")
private BigDecimal adLmt;

@Temporal( TemporalType.DATE)
@Column(name="BEG_DT")
private Date begDt;

@Column(name="BEG_TIME")
private String begTime;

@Column(name="CST_RMA")
private BigDecimal cstRma;

private String deal;

@Temporal( TemporalType.DATE)
@Column(name="END_DT")
private Date endDt;

@Column(name="END_TIME")
private String endTime;

@Temporal( TemporalType.DATE)
@Column(name="ENT_DT")
private Date entDt;

@Column(name="ENT_TIME")
private String entTime;

@Column(name="ITM_CD")
private String itmCd;

@Column(name="PC_TP")
private String pcTp;

@Temporal( TemporalType.DATE)
@Column(name="PLUC_DT")
private Date plucDt;

@Column(name="PREV_PERM_RET")
private BigDecimal prevPermRet;

@Column(name="PROMO_KEY_VALUE")
private String promoKeyValue;

@Column(name="RET_PRC")
private BigDecimal retPrc;

public A() {
}

public APK getId() {
    return this.id;
}

public void setId(APK id) {
    this.id = id;
}

public String getActionCd() {
    return this.actionCd;
}

public void setActionCd(String actionCd) {
    this.actionCd = actionCd;
}

public BigDecimal getAdLmt() {
    return this.adLmt;
}

public void setAdLmt(BigDecimal adLmt) {
    this.adLmt = adLmt;
}

public Date getBegDt() {
    return this.begDt;
}

public void setBegDt(Date begDt) {
    this.begDt = begDt;
}

public String getBegTime() {
    return this.begTime;
}

public void setBegTime(String begTime) {
    this.begTime = begTime;
}

public BigDecimal getCstRma() {
    return this.cstRma;
}

public void setCstRma(BigDecimal cstRma) {
    this.cstRma = cstRma;
}

public String getDeal() {
    return this.deal;
}

public void setDeal(String deal) {
    this.deal = deal;
}

public Date getEndDt() {
    return this.endDt;
}

public void setEndDt(Date endDt) {
    this.endDt = endDt;
}

public String getEndTime() {
    return this.endTime;
}

public void setEndTime(String endTime) {
    this.endTime = endTime;
}

public Date getEntDt() {
    return this.entDt;
}

public void setEntDt(Date entDt) {
    this.entDt = entDt;
}

public String getEntTime() {
    return this.entTime;
}

public void setEntTime(String entTime) {
    this.entTime = entTime;
}

public String getItmCd() {
    return this.itmCd;
}

public void setItmCd(String itmCd) {
    this.itmCd = itmCd;
}

public String getPcTp() {
    return this.pcTp;
}

public void setPcTp(String pcTp) {
    this.pcTp = pcTp;
}

public Date getPlucDt() {
    return this.plucDt;
}

public void setPlucDt(Date plucDt) {
    this.plucDt = plucDt;
}

public BigDecimal getPrevPermRet() {
    return this.prevPermRet;
}

public void setPrevPermRet(BigDecimal prevPermRet) {
    this.prevPermRet = prevPermRet;
}

public String getPromoKeyValue() {
    return this.promoKeyValue;
}

public void setPromoKeyValue(String promoKeyValue) {
    this.promoKeyValue = promoKeyValue;
}

public BigDecimal getRetPrc() {
    return this.retPrc;
}

public void setRetPrc(BigDecimal retPrc) {
    this.retPrc = retPrc;
}
}

APK:     @Embeddable     公共类APK实现Serializable {

private static final long serialVersionUID = 1L;

@Column(name="SKU_NUM")
private String skuNum;

@Column(name="PRC_ZONE_CD")
private String prcZoneCd;

@Column(name="PRC_GRP_CD")
private String prcGrpCd;

@Column(name="PC_NUM")
private String pcNum;

public APK() {
}
public String getSkuNum() {
    return this.skuNum;
}
public void setSkuNum(String skuNum) {
    this.skuNum = skuNum;
}
public String getPrcZoneCd() {
    return this.prcZoneCd;
}
public void setPrcZoneCd(String prcZoneCd) {
    this.prcZoneCd = prcZoneCd;
}
public String getPrcGrpCd() {
    return this.prcGrpCd;
}
public void setPrcGrpCd(String prcGrpCd) {
    this.prcGrpCd = prcGrpCd;
}
public String getPcNum() {
    return this.pcNum;
}
public void setPcNum(String pcNum) {
    this.pcNum = pcNum;
}

public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof APK)) {
return false;
}
APK castOther = (APK)other;
return 
this.skuNum.equals(castOther.skuNum)
&& this.prcZoneCd.equals(castOther.prcZoneCd)
&& this.prcGrpCd.equals(castOther.prcGrpCd)
&& this.pcNum.equals(castOther.pcNum);

}

public int hashCode() {
final int prime = 31;
int hash = 17;
hash = hash * prime + this.skuNum.hashCode();
hash = hash * prime + this.prcZoneCd.hashCode();
hash = hash * prime + this.prcGrpCd.hashCode();
hash = hash * prime + this.pcNum.hashCode();

return hash;
}
}

0 个答案:

没有答案