Shipment类
private String id;
private String shipmentdate;
private String kehuName;
private String sellName;
private Set<ShipmentProduct> shipmentProducts=new HashSet<ShipmentProduct>(0);shipmentproduct类
private String product_id;
private Shipment shipment;
private String productName;
private String productSerial;
private String alwaysSerial;
private String ybSerial;
private String checker;
private String grade;
private String dytSerial;
private String qdSerial;
private String software;
private String re;
两者是一对多的关系。Dao层实现代码
public List findYBBydate(String startDate, String endDate) {
Session session=HibernateSessionFactory.getSession();
Query query=session.createSQLQuery("select * from shipment s,shipment_product sp where s.id=sp.shipmentid and s.shipmentdate between ? and ? and sp.yb_serial is not null");
query.setString(0,startDate);
query.setString(1,endDate);
return query.list();
}目前能从dao层中能获得一个list集合对象,怎样获得shipment和shipmentproduct类中的属性?

解决方案 »

  1.   

    你得到是一个OBJECT 数组,要去除值,要按索引取值,为何不用HIbernate 做呢,有了映射文件,和对应得实体类,很容易获得其属性的.........
      

  2.   

    再写个bean
    把Shipment类和shipmentproduct类
    属性加进去,如果重复的只要一个就行了!
    这样可以不?
      

  3.   

    你的HQL语句有问题应该使用类名,而不是表名.("select * from shipment s,shipment_product sp where s.id=sp.shipmentid and s.shipmentdate between ? and ? and sp.yb_serial is not null");
    ((Object[])list.get(i))[0]--->shipment 
    ((Object[])list.get(i))[1]--->shipment_product 
    你可以使用相似的语句:("from shipment_product sp where sp.shipment.shipmentdate between ? and ? and sp.yb_serial is not null"); 这样出来就只有shipment_product 了,你就可以使用((shipment_product)(list.get(i)))来读取相关属性了....如果是用EL,也就更容易了
    sp.shipment.xxxx
    sp.xxx