Hibernate3实现one-to-one级联插入

阅读更多
主键关联外键方式create table t_cust(I_FXM_CUST serial);
create table t_settle_acct(I_FXM_SETTLE_ACCT SERIAL, I_FXM_CUST INT)主表映射对象:
/**
 * @description 客户信息表
 * @author Jason.T
 * @date 2007-1-30
 * 
 * @hibernate.class 
 *  table="t_cust"
 */
public class Customer implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 客户内部编号
	 */
	private Integer iFXMCust;

	
	/**
	 * 清算参数
	 */
	private FXMSettlePara settlePara;

		/**
	 * @hibernate.id 
	 *  column="i_fxm_cust" 
	 *  generator-class="native"
	 * @return
	 */
	public Integer getIFXMCust() {
		return iFXMCust;
	}

	
	public void setIFXMCust(Integer customerId) {
		iFXMCust = customerId;
	}

	
	public void setTxnPara(FXMCustTxnPara txnPara) {
		this.txnPara = txnPara;
	}

	/**
	 * @hibernate.one-to-one 
	 * cascade="all"
	 * outer-join="true"
	 * foreign-key="I_FXM_CUST"
	 * @return
	 */
	public FXMSettlePara getSettlePara() {
		return settlePara;
	}

	public void setSettlePara(FXMSettlePara settlePara) {
		this.settlePara = settlePara;
	}
}

子表映射对象:
/**
 * @description 客户清算参数表
 * @author Jason.T
 * @date 2006-12-25
 * 
 * @hibernate.class
 * 	table="t_settle_acct"
 */
public class FXMSettlePara implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 内部编号
	 */
	private Integer iFXMSettleAcct;
	
	private Customer cust;

	/**
	 * @hibernate.id
	 * 	column="i_fxm_settle_acct"
	 *  generator-class="native"
	 * @return
	 */
	public Integer getIFXMSettleAcct() {
		return iFXMSettleAcct;
	}

	public void setIFXMSettleAcct(Integer settleAcct) {
		iFXMSettleAcct = settleAcct;
	}


	/**
	 * @hibernate.many-to-one 
	 * column="I_FXM_CUST"
	 * unique="true"
	 */
	public Customer getCust() {
		return cust;
	}

	public void setCust(Customer cust) {
		this.cust = cust;
	}
	
}


插入记录:
Customer cust = new Customer();
FXMSettlePara settlePara = new FXMSettlePara();
settlePara.setCust(cust);
cust.setSettlePara(settlePara);
  


  

  
  
    
  

  
  

你可能感兴趣的:(Hibernate)