Hello all, I am trying to solve a problem ... I am able to return the correct number of data records, but I cannot print out the data let me explain:
My Hibernate Dao: return (Collection<InspectionsReportRow>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { inspectionStatusReportQuery = "SELECT {io.*}, {orgr.*} " + "FROM igems.l_insp_category lic " + "INNER JOIN igems.l_insp_type lit " + " ON ( lit.insptypeid = lic.insptypeid) " + "INNER JOIN igems.insp i " + " ON ( i.inspcategoryid = lic.inspcategoryid) " + "INNER JOIN igems.l_insp_status lis " + " ON ( i.inspstatusid = lis.inspstatusid) " + "INNER JOIN igems.insp_org io " + " ON ( i.inspid = io.inspid) " + "INNER JOIN igems.org o " + " ON ( o.orgid = io.orgid) " + "LEFT OUTER JOIN igems.org_remark orgr " + " ON ( orgr.inspid = i.inspid " + " AND orgr.orgid = io.orgid " + " AND orgr.nextremarkid is null " + " AND orgr.remarkstatusid = <id>) " + "WHERE " ...
Query query = session.createSQLQuery(inspectionStatusReportQuery).addEntity("io", AssignedOrganization.class) .addEntity("orgr", OrganizationRemark.class) .addEntity("io", AssignedOrganization.class) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .setCacheMode(CacheMode.REFRESH); log.info("size = " + query.list().size());
I get the correct number of records (I compare the above query with what is pasted in SQL and get the same results); however, when I try and print out the data of the two classes (io or orgr) in the service layer, I get an error:
// this is what calls the above method Collection<InspectionsReportRow> inspectionsReportRows = assignedOrganizationDao.findAllForInspectionStatusReport ( command, organization, inspectionTypes, startDate, endDate, inspectionStatuses);
// if I print the size, it matches the size from the previous method log.info("size from service layer = " + inspectionsReportRows.size());
// If I try to loop through and print the data I get an error ... for (InspectionsReportRow irr : inspectionsReportRows) { log.info(irr.getAssignedOrganization().getAttribute...); } // I believe the above statement is bombing on the for statement, not the log.info statement.
// My POJO for InspectionsReportRow is defined as
private AssignedOrganization assignedOrganization; // maps to the io SQL alias private OrganizationRemark organizationRemark; // maps to the orgr SQL alias
public AssignedOrganization getAssignedOrganization() { return assignedOrganization; } public void setAssignedOrganization(AssignedOrganization assignedOrganization) { this.assignedOrganization = assignedOrganization; } public OrganizationRemark getOrganizationRemark() { return organizationRemark; } public void setOrganizationRemark(OrganizationRemark organizationRemark) { this.organizationRemark = organizationRemark; }
Any help would be greatly appreciated. My fallback is to write a POJO that returns all primitive data types (string, int, dates), but I would love to implement it by using the dynamic classes (AssignedOrganization and OrganizationRemark).
Thanks in advance for the help!
|