Hi All,
I'm working on a Struts Application that uses Hibernate. I'm just learning Hibernate and I'm having some trouble getting things to work.
In the end I'm trying to execute the HQL equivalent of the following SQL:
Code:
SELECT D.DEFECTID, D.DESCRIPTION, P.DESCRIPTION as Priority, D.REPORTDATETIME as ReportDate, SF.USERNAME as Reporter, FA.AreaName as FunctionalArea,
S.Description as Status, D.SEVERITY as Severity FROM Priority P
JOIN Defect D on P.priorityId = D.priorityId
JOIN Status S on S.statusId = D.statusId
JOIN functionalArea FA on FA.functionalAreaId = D.functionalAreaId
JOIN Staff SF on SF.staffId = D.reporterUserId
I would like the result to be a list of Defect Objects. Since I'm new to hibernate I thought I would simplify my join to begin with and try executing each of the following:
Code:
//sb.append("select fa.areaName From Defect d JOIN d.functionalAreas as fa");
sb.append("select st.userName From Defect d JOIN d.staff as st");
results = session.createQuery(sb.toString()).list();
While each of the two statements above execute without error I'm not getting any rows returned. My Defect Hibernate Mapping File looks like below:
Code:
<class name="Defect" table="Defect">
<id name="defectId" type="integer" column="DEFECTID">
<generator class="native"/>
</id>
<property name="description" type="string"/>
<property name="priorityId" type="integer"/>
<property name="reportDateTime" type="date" column="REPORTDATETIME" />
<property name="reporterUserId" type="integer"/>
<property name="functionalAreaId" type="integer"/>
<property name="statusId" type="integer"/>
<property name="severity" type="string"/>
<property name="teamLeadId" type="integer"/>
<property name="detectionDateTime" type="date"/>
<property name="estFixTime" type="integer"/>
<property name="actFixTime" type="integer"/>
<property name="statusDate" type="date"/>
<property name="assignedToUserId" type="integer"/>
<property name="assignedToDate" type="date"/>
<property name="fixedByUserId" type="integer"/>
<set name="staff" table="STAFF">
<key column="staffId" />
<one-to-many class="Staff"/>
</set>
<set name="functionalAreas" table="FUNCTIONALAREA">
<key column="functionaAreaId" />
<one-to-many class="FunctionalArea"/>
</set>
</class>
</hibernate-mapping>
Code:
A portion of my Defect Class is shown below:
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.swing.JApplet;
import org.apache.bsf.util.event.adapters.java_awt_event_ActionAdapter;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
public class Defect extends ActionForm
{
//Form Bean For the Defect Entry Screen
private Integer defectId;
private String description;
private Integer priorityId;
private java.sql.Date reportDateTime;
private Integer reporterUserId;
private Integer functionalAreaId;
private Integer statusId;
private String severity;
private Integer teamLeadId;
private java.sql.Date detectionDateTime;
private Integer estFixTime;
private Integer actFixTime;
private java.sql.Date statusDate;
private Integer assignedToUserId;
private java.sql.Date assignedToDate;
private Integer fixedByUserId;
private Set functionalAreas;
private Set staff;
public Set getStaff() {
return staff;
}
public void setStaff(Set staff) {
this.staff = staff;
}
public Set getFunctionalAreas() {
return functionalAreas;
}
public void setFunctionalAreas(Set functionalAreas) {
this.functionalAreas = functionalAreas;
}
public java.sql.Date getReportDateTime() {
return reportDateTime;
}
public void setReportDateTime(java.sql.Date reportDateTime) {
this.reportDateTime = reportDateTime;
}
blah, blah, blah
}
Can anyone tell me what I'm doing wrong?
Thanks so much,
Rob