-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to find a particular record out of 1000records using hql
PostPosted: Thu Mar 03, 2011 12:51 am 
Newbie

Joined: Thu Mar 03, 2011 12:42 am
Posts: 4
Hi to all ,

i am new to hibernate ,

i am tring to retrive data from database using hql , the code which i used is---

i am getting the records, but help me to ger a better one

Thanks for support..
Session s=null;
try
{
SessionFactory sf=new Configuration().configure().buildSessionFactory();
s=sf.openSession();

String sql="from FacultyCourses";

Query q=s.createQuery(sql);

for(Iterator it=q.iterate();it.hasNext();)
{
FacultyCourses obj=(FacultyCourses) it.next();

int a=obj.getNumberOfStudentEnrolled();

FacultyCoursesId aa= obj.getId();
String ap=aa.getFacultyId();
if(ap.equalsIgnoreCase("Fact519"))
{
System.out.println("fact:"+ obj.getDateCourseStarted());
break;
}


}


Top
 Profile  
 
 Post subject: Re: How to find a particular record out of 1000records using hql
PostPosted: Thu Mar 03, 2011 2:44 am 
Regular
Regular

Joined: Fri Nov 12, 2010 4:13 am
Posts: 81
Location: India
SessionFactory sf=new Configuration().configure().buildSessionFactory();

s=sf.openSession();

List searchresult = null;

Criteria crit = session.createCriteria(FacultyCourses.getClass());

crit.add(Restrictions.eq(columnName, value)); //Put columname which u require and value equal to what u r expecting

searchresult = crit.list();

s.flush();

s.close;

return searchresult; //this searchresult will have your desired result.

_________________
Thanks & Regards,
Chirag


Top
 Profile  
 
 Post subject: Re: How to find a particular record out of 1000records using hql
PostPosted: Thu Mar 03, 2011 5:57 am 
Newbie

Joined: Thu Mar 03, 2011 12:42 am
Posts: 4
Thanks chirag.naikec for your time and concern

still i am not getting what i want is ---

courcetable
column1
column2
column3
column4
column5

base on one column1 a want to find any record out of 1000

i.e Query q=selet column1 from coursetable where column1='some thing';

in iteration loop i am able to acees remaining columns of particular record

IF any knows this concept help me...


Top
 Profile  
 
 Post subject: Re: How to find a particular record out of 1000records using hql
PostPosted: Thu Mar 03, 2011 6:02 am 
Newbie

Joined: Thu Mar 03, 2011 12:42 am
Posts: 4
Thanks chirag.naikec for your time and concern

still i am not getting what i want is ---

courcetable
column1
column2
column3
column4
column5

base on one column1 a want to find any record out of 1000

i.e Query q=selet column1 from coursetable where column1='some thing';

in iteration loop i am able to acees remaining columns of particular record

IF any knows this concept help me...


Top
 Profile  
 
 Post subject: Re: How to find a particular record out of 1000records using hql
PostPosted: Thu Mar 03, 2011 11:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 11, 2009 2:26 am
Posts: 29
Query query = session.createQuery("select f.dateCourseStarted from FacultyCourses f where f.id.facultyId = :facultyId");
query.setParameter("facultyId","Fact519");
Object dateCourseStarted = query.getSingleResult();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.