-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem with createSqlQuery (addEntity and possibly addJoin)
PostPosted: Sun Jul 13, 2014 9:11 pm 
Newbie

Joined: Sun Jul 13, 2014 8:49 pm
Posts: 1
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.