Hi,all
parent table:sale_contract
child table:sale_bill
sale_contract's PK is cont_no,need to assign value manually(not identity or sequence)
sale_bill'FK is cont_no
child will control the association(inverse="true")
middlegen create mapping files:SaleContract.hbm.xml,SaleBill.hbm.xml
and pojos: SaleContract.java,SaleBill.java
that time,middlegen will add a SaleCntract attribute to replace the cont_no attribute automaticlly in SaleBill.java
question is there:when I insert a new record,I can't set the cont_no because there has not a setter/getter of cont_no attribute in the SaleBill.java
SaleContract contract=new SaleContract();//parent
SaleBill bill=new SaleBill();//child
//there is no bill.setContNo()
bill.setBillNo(new Long(77));
bill.setBookId("77");
....
bill.setContract(contract);
contract.getDetail().add(bill);
session.save(contract);
tx.commit();
session.close();
how can I do?
|