-->
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: getting distinct Result set using HQL createquery
PostPosted: Mon Aug 02, 2010 10:21 am 
Newbie

Joined: Mon Aug 02, 2010 10:03 am
Posts: 1
i want to get the distinct results. i am using the following HQL. for it.

this is a one to many relation ship i which student can take admission in many courses.

the hbm code for it is
Code:
<class name="com.vaannila.course.Course" table="COURSES_T">
      
      <id name="courseId" type="long" column="COURSE_ID"></id>
      <property name="courseName" type="string" column="COURSE_NAME" />
      
      <!-- <many-to-one name="student" class="com.vaannila.course.Student"
         column="STUDENT_ID"></many-to-one> -->
   </class>
   
   <class name="com.vaannila.course.Student" table="STUDENT_T" >
      
      <id name="studentId" type="long" column="STUDENT_ID"></id>
      <property name="name" type="string" column="STUDENT_NAME" />
      
      <list name="course" lazy="true">
         <key column="COURSE_ID"></key>
         <list-index column="lindex"/>
         <one-to-many class="com.vaannila.course.Course"></one-to-many>
      </list>


in DB the student tale has 1 record and the Course table has 2 records.

i am using the code for HQL

Code:
List courses = session.createQuery("from Student s inner join fetch s.course c where s.studentId=20101").list();


when i run this it populates the following result

Quote:
select student0_.STUDENT_ID as STUDENT1_1_0_, course1_.COURSE_ID as COURSE1_0_1_, student0_.STUDENT_NAME as STUDENT2_1_0_, course1_.COURSE_NAME as COURSE2_0_1_, course1_.COURSE_ID as COURSE1_0__, course1_.lindex as lindex0__ from STUDENT_T student0_ inner join COURSES_T course1_ on student0_.STUDENT_ID=course1_.COURSE_ID where student0_.STUDENT_ID=20101
++>2 // <-- the students record count is printed.
Kumar
-->3
null //<-- dont know why and from where this null is comming still loooking into it.
com.vaannila.course.Course@1815338
IT //<-- this result is ok.
com.vaannila.course.Course@1815338
IT //<-- here it is duplicating the 1st record. its not getting the fetched record.
Kumar
-->3
null
com.vaannila.course.Course@1815338
IT
com.vaannila.course.Course@1815338
IT


if the gebrated SQL query is run in the sql server then it populates the proper result.

Can any one help me in this?

thanking you in advance.


Regards,

Kumar Sabnis


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.