2015-11-22 27 views
0

我遇到了@OneToOne單向映射問題。家長PK沒有保存在加入的子欄中。例如customer_payment的invoice_master_id_pay應與CustomerInvoiceMaster的customer_invoice_master一起插入。OneToOne加入專欄問題

這是映射。

@Entity 
@Table(name = "customer_invoice_master") 
public class CustomerInvoiceMaster { 

@Id 
private int invoiceMasterId; 

// invoice_master_id_pay should be populated with 
// CustomerInvoiceMaster customer_invoice_master PK. This is not 
// not happening. Row is created with zero value 
@OneToOne(cascade = CascadeType.ALL) 
@JoinColumn(name = "invoice_master_id_pay") 
private CustomerPayment customerPayment; 

} 

@Entity 
@Table(name="customer_payment") 
public class CustomerPayment{ 
    @Id 
    private int customerPaymentId; 

... 
} 

回答

0

你上invoice_master_id_pay所示將不存儲父CustomerInvoiceMaster PK的代碼,它是相反的,這一一對一映射將存儲customerPaymentIdinvoice_master_id_pay

父母是使用加入列引用孩子的人。

+0

謝謝。這就是我之前想的。我同意你的迴應。 –

0
CustomerPayment cp=new CustomerPayment(); 
// assign properties to cp; 
CustomerInvoiceMaster cim=new CustomerInvoiceMaster(); 
// assign properties to cti (including cp); 
... 
session.save(cim); // would save both cp,cim; 

如果你想session.save(cp);保存兩個CP,CIM使用OneToOne雙向關聯。