我正在研究struts2和hibernate。我在我的程序中实现一对多映射时遇到问题。我从jsp获得了list的null值。请帮帮我,有代码:
父pojo类是:`
private static final long serialVersionUID = 1L;
private int id;
private String voucherno;
private String vendor_name;
private String address;
private Integer vendor_invoice_no;
private Date invoice_date;
private Date due_date;
private Date user_date;
private String currency;
private Double exRate;
private Double totalAmt;
private Double totalSTex;
private Double tds_amount;
private Double s_tax_amount;
private String tds_section;
private Double tds_cost;
private Double tdsamount;
private Double payable_amount;
private String narration;
private List<Payable_datail> recievable_detail ;
子pojo类是:
private Integer payable_Id;
private String chargeHead;
private String description;
private Double amount;
private Double tamount;
private String st_chargehead;
private String s_tax_list;
private String service_tax_category;
private Double s_tax;
private Double edu_case;
private Double high_case;
private Double total_s_tax;
private Payable_detaildto payable_detailDto;
父hbm文件是:
<list name="recievable_detail" inverse="false" lazy="true" cascade="all">
<key column="ID" ></key>
<index column="index"></index>
<one-to-many class="com.envosys.dto.Payable_datail"/>
</list>
Child hbm文件是:
<many-to-one name="payable_detailDto" class="com.envosys.dto.Payable_detaildto" fetch="join" unique="false" update="true" insert="true" optimistic-lock="true" not-found="exception" embed-xml="true">
<column name="ID" />
</many-to-one>
和jsp是我使用此列表的地方“recievable_detail”:是
cell0.innerHTML = "<td align='left'><input id='chargeHead"+count+"' name='recievable_detail["+count+"].chargeHead' type='text' value='"+chargehead+"' class='text ui-widget-content ui-corner-all chargeHead' size=50 ' onblur=\"check("+count+")\" ><input type =\"hidden\" id='set_service"+count+"' name = \"set_service\"> ";
cell1.innerHTML = "<td align='left'><textarea id='description"+count+"' name='recievable_detail["+count+"].description' type='textarea' rows=\"1\" cols=\"30\" class='text ui-widget-content ui-corner-all'> ";
cell2.innerHTML = "<td align='left'><input id='amount"+count+"' name='recievable_detail["+count+"].amount' type='text' value="+amount+" class='text ui-widget-content ui-corner-all' onkeyup='data1()'> ";
cell3.innerHTML = "<td align='left'><input id='tamount"+count+"' name='recievable_detail["+count+"].tamount' type='text' value="+tamount+" class='text ui-widget-content ui-corner-all'> ";
cell4.innerHTML = "<a onclick=\"removeRow("+count+")\" align=\"center\"><img src=\"images/Minus.png\"/></a></td>";
我的问题是我无法在子类和父类之间进行映射,因为我得到列表的值“recievable_detail”在父类的getter和setter中为null。请帮帮我,给我任何想法和合适的建议。
`
答案 0 :(得分:0)
必须使用正确类型的空集合初始化所有集合属性;在你的情况下
private List<Payable_datail> recievable_detail = new ArrayList<Payable_datail> ;