I am using hibernate 3.0.
I am having problem in fetching results by Hibernate query.
I am having following objects
Entry,Queue,Task.
Entry has one to many relationship with Tasks.
Queue has many to one relationship with Entry.
Following is the query I am executing.
Code:
getHibernateTemplate().find("from Entry e join fetch e.queue " +
where (e.status = ? or e.status = ?) and e.queue.id = ? and e.tasks.appointmentDate BETWEEN ? AND ? order by e.tasks.appointmentDate",
new Object[]{new Integer(Constants.OPEN), new Integer(Constants.FORWARD), queueId,today, afterthirtydays});
The problem is for Entry which has more than one Task. It is returning the more rows as result.
Suppose if Entry has 2 Tasks then in results I am getting 4 rows.If Entry has 3 Tasks then I am getting 9 rows
in result.
folloeing is the query I am getting on console.
Code:
Hibernate: select entry0_.WORKITEM_ID as WORKITEM1_6_0_,
queue1_.QUEUE_ID as QUEUE1_1_1_, entry0_.VERSION as VERSION6_0_,
entry0_.PATIENT_NAME as PATIENT3_6_0_, entry0_.CPI_NUMBER as CPI4_6_0_,
entry0_.BEGIN_DATE as BEGIN5_6_0_, entry0_.CREATED as CREATED6_0_,
entry0_.STATUS as STATUS6_0_, entry0_.USER_ID as USER8_6_0_,
entry0_.SUSPEND_BY as SUSPEND9_6_0_, entry0_.FORWARD_BY as FORWARD10_6_0_,
entry0_.FORWARD_TO as FORWARD11_6_0_, entry0_.SUSPEND_DATE as SUSPEND12_6_0_,
entry0_.ORGAN as ORGAN6_0_, entry0_.ORGAN_2 as ORGAN14_6_0_,
entry0_.RECORD_ID as RECORD15_6_0_, entry0_.EPISODE as EPISODE6_0_,
entry0_.PATIENT_SEX as PATIENT17_6_0_, entry0_.PATIENT_PHONE_NBR as PATIENT18_6_0_,
entry0_.CONTACT_PHONE_NBR as CONTACT19_6_0_, entry0_.PATIENT_DOB as PATIENT20_6_0_,
entry0_.FORWARD_COMMENT as FORWARD21_6_0_, entry0_.QUEUE_ID as QUEUE22_6_0_,
entry0_.PATIENT_ID as PATIENT23_6_0_,queue1_.VERSION as VERSION1_1_,
queue1_.QUEUE_NAME as QUEUE3_1_1_, queue1_.OT_TYPE as OT4_1_1_,
queue1_.NAME_RULE as NAME5_1_1_, queue1_.CREATED as CREATED1_1_
from TBW_ENTRY entry0_, TBW_QUEUE queue1_, TBW_TASK tasks2_, TBW_TASK tasks3_
where entry0_.WORKITEM_ID=tasks3_.WORKITEM_ID and entry0_.WORKITEM_ID=tasks2_.WORKITEM_ID
and entry0_.QUEUE_ID=queue1_.QUEUE_ID and (entry0_.STATUS=? or entry0_.STATUS=?)
and entry0_.QUEUE_ID=? and (tasks2_.APPOINTMENT_DATE between ? and ?) order by tasks3_.APPOINTMENT_DATE
In the "from" clause in above sql I am getting TBW_TASK two times.
I will appriciate if some body helps me out.
Thanks.