-->
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: How to search object within objects using Criteria
PostPosted: Tue Dec 07, 2010 1:50 pm 
Newbie

Joined: Thu Dec 02, 2010 11:36 am
Posts: 2
Hi all,

I have a student table which has following data
a) serialno <primary key>
b) firstname
c) lastname

I have a registration table which has following data
a) id <primary key>
b) serialno <this is the serial no from the student table>
c) registrationno


My Student.java annotations is as below
Code:
@Entity
@Table(name = "student")
public class Student implements Serializable {
     
   private RegistrationInfo regninfo;
   
   public void setRegninfo(RegistrationInfo regninfo) {
      this.regninfo = regninfo;
   }

   @OneToOne
   @JoinColumn(name="regninfo_id")
   public RegistrationInfo getRegninfo() {
      return regninfo;
   }

   private DDInfo ddinfo;
   
   @OneToOne
   @JoinColumn(name="ddinfo_id")   
   public DDInfo getDdinfo() {
      return ddinfo;
   }

   public void setDdinfo(DDInfo ddinfo) {
      this.ddinfo = ddinfo;
   }


My search code StudentDAOImpl.java is below
Code:
public List<Student> queryStudent(String fname,String lname,String regnno)
   {
       Criteria criteria = session.createCriteria(Student.class);

       if(fname!=null && fname!="")
       {
          criteria.add(Restrictions.eq("std_fname", fname));
       }
       if(lname!=null && lname!="")
       {
          criteria.add(Restrictions.eq("std_lname", lname));
       }

                //to determine whether any registration info parameters is passed or not
                 // if yes then add in the query
       boolean registrationflag=false;
       if(regnno!=null && regnno!="")
       {
                         
                        // HERE IS THE PART WHERE I AM HAVING PROBLEM
                         criteria.createAlias("regninfo",reg);   
          registrationflag=true;
       }
                 if(registrationflag)
       { 
          if((regnno!=null && regnno!=""))
          {
             criteria.add(Restrictions.eq("regnno", regnno));
          }
                  }



My search condition is as below
1) On students page, when i query, only students information will be queried << This is working fine >>
2) On registration page, when i query, students+registration information will be queried.
--> a) Without passing any search items, i get all the values in Student + Registration details << This is working fine >>
--> b) When passing Student's information,i get all the required values for Student + Registration details << This is working fine >>
--> c) When passing Student + registration detail, getting lots of errors << This is not working >>

My question is as below
1) Since Criteria criteria = session.createCriteria(Student.class); already gave me all necessary details ,
How do i search the registrationinfo object inside the Student object for values
Eg If regnno = 15 , how do i list the Student with regnno=15

I have tried the following but to not avail
1) criteria.createCriteria("regninfo"); // org.hibernate.QueryException: not an association: regninfo
2) criteria.createCriteria("regninfo_id"); //org.hibernate.QueryException: could not resolve property: regninfo_id
3) criteria.createAlias("regninfo_id","reg"); //org.hibernate.QueryException: could not resolve property: regninfo_id
4) criteria.createAlias("regninfo","reg"); //org.hibernate.QueryException: not an association: regninfo

I have search the net a lot, but doesn't seem to get the correct answer .
Any help / guide is mostly appreciated.


Regards,
Vanlal


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.