-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problems with Hibernate HQL Join Query
PostPosted: Fri Nov 20, 2009 11:21 am 
Newbie

Joined: Fri Nov 20, 2009 10:56 am
Posts: 3
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


Top
 Profile  
 
 Post subject: Re: Problems with Hibernate HQL Join Query
PostPosted: Sun Nov 22, 2009 1:35 pm 
Newbie

Joined: Mon Nov 28, 2005 2:35 pm
Posts: 14
Hi,

I don't know if what you are planning works. What I can tell you is, that it works to join an entity.
For this create a class FunctionArea and map it. Then you will be able to use it in a join query.

See here
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html

Hope this helps

foster


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

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.