【问题标题】:I got null value when i map one to many mapping using list in hibernate当我在休眠中使用列表映射一对多映射时,我得到了空值
【发布时间】:2014-03-07 10:34:03
【问题描述】:

我在 struts2 和 hibernate 上工作。当我在我的程序中实现一对多映射时遇到问题。我从 jsp 得到了 list 的空值。请帮我有代码:

父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> 

子 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>";

我的问题是我无法在子类和父类之间进行映射,因为我在父类的 getter 和 setter 中得到的列表“recievable_detail”的值为 null。请帮助我,给我任何想法和合适的建议。

    `

【问题讨论】:

    标签: java database hibernate struts dto


    【解决方案1】:

    所有集合属性必须用适当类型的空集合初始化;你的情况

    private List&lt;Payable_datail&gt; recievable_detail = new ArrayList&lt;Payable_datail&gt; ;

    【讨论】:

      猜你喜欢
      • 2023-03-14
      • 2020-05-20
      • 2011-04-07
      • 1970-01-01
      • 2011-10-25
      • 1970-01-01
      • 2014-08-20
      • 2019-02-19
      相关资源
      最近更新 更多