-->
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.  [ 7 posts ] 
Author Message
 Post subject: how to add one criteria to another criteria
PostPosted: Sat May 03, 2008 5:59 am 
Beginner
Beginner

Joined: Fri Sep 28, 2007 4:58 am
Posts: 21
Location: Chennai, India
HI All,

i am using two criteria's. i want to combine these two criteria's to one criteria. please let me know how to do.

actually what i did?

Criteria schdlInstanceCriteria = session.createCriteria(ReportScheduleInstance.class,"scheduleInstance")
.createCriteria("scheduleInstance.report", "report")
.createCriteria("scheduleInstance.clientCompany", "clientCompany")
.setProjection(Projections.projectionList()
.add(Projections.property("scheduleInstance.reptSchdlInstanceId"))
.add(Projections.property("scheduleInstance.isScheduled"))
.add(Projections.property("scheduleInstance.reptScheduleDesc"))
.add(Projections.property("clientCompany.clientCompId")))
.add(Restrictions.eq("scheduleInstance.isScheduled", new Integer(reportSearchVO.getGeneratedMethod())))
.add(Restrictions.eq("report.reprotDefId", new Long(reportSearchVO.getReportId())));



if(reportSearchVO.getCompanyNumber()!= 0 ){
Criteria accountCriteria = session.createCriteria(ClientAccount.class,"clientAccount")
.createCriteria("clientAccount.clientCompany", "clientCompany")
.add(Restrictions.eq("clientCompany.companyNumber", new Long(reportSearchVO.getCompanyNumber())));
if(reportSearchVO.getAccountNumber()!=0){
accountCriteria.add(Restrictions.eq("clientAccount.clientAcctNum", new Long(reportSearchVO.getAccountNumber())));
}
//schdlInstanceCriteria = schdlInstanceCriteria.createCriteria(accountCriteria);
}

the above thing i want to combine into schdlInstanceCriteria . please let me know how to do. please do the needful.

_________________
Purushotham Podaralla


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 03, 2008 12:48 pm 
Beginner
Beginner

Joined: Fri Apr 11, 2008 1:48 am
Posts: 36
Hello venkatpuru,

you could try to use DetachedCriteria's. Have a look at my example:

Code:
      List<Person> result = new ArrayList<Person>();
      _session = ((HibernateEntityManager) em).getSession();
      Criteria crit = _session.createCriteria(Person.class);
     
      DetachedCriteria noShirts=
          DetachedCriteria.forClass(Person.class)
              .createAlias("clothes ", "bi")
              .add(Restrictions.eq("bi.name", "shirt"))
              .setProjection(Projections.id());

      crit.add(Subqueries.notExists(noShirts));   
     
      result = crit.list();


There is even a Subqueries.exists(dc) method which you will need. Please let me know if this post was helpful.

EDIT: You will nee following Subquery: Subqueries.propertyEq(String propertyName, DetachedCriteria dc)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 05, 2008 1:18 am 
Beginner
Beginner

Joined: Fri Sep 28, 2007 4:58 am
Posts: 21
Location: Chennai, India
yeah thinkpad, its useful for me. thanks for giving a query .

_________________
Purushotham Podaralla


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 06, 2008 9:19 am 
Beginner
Beginner

Joined: Fri Sep 28, 2007 4:58 am
Posts: 21
Location: Chennai, India
Hi Thinkpad,

i did according to your instructions. but i got an error like

org.hibernate.MappingException: Unknown entity: null

please let me know the solution. thanks for cooperation.

_________________
Purushotham Podaralla


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 06, 2008 12:14 pm 
Beginner
Beginner

Joined: Fri Apr 11, 2008 1:48 am
Posts: 36
You have to make the alias in the crit main object too.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 06, 2008 2:58 pm 
Beginner
Beginner

Joined: Fri Apr 11, 2008 1:48 am
Posts: 36
Sthe last information was wrong. You have to put the alias:

Code:
.createAlias("clothes ", "bi")


into the main criteria ("crit" in my example). You dont need the alias in the detached criteria.

Please dont forget to rate my Posting if I could help you.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 07, 2008 3:12 am 
Beginner
Beginner

Joined: Fri Sep 28, 2007 4:58 am
Posts: 21
Location: Chennai, India
Hi All,

i want to write a createCriteria with projections. i am providing the details what i want to implement.
the tables are :
tables:-------- columns :
instance---- instance_id
history----- history_id, instance_id, runtime
param----- param_id, instance_id, value

the relationship is like this instance to history is one to many, and instance to param is also one to many. i want combine all the columns from both tables to a singele row. i have a dought like this we can get columns from instance to history is 3 rows and from instance to param 2 rows. how to genarate a single query if the rows get's like this. please do the needful.

thanks & regards

Purushotham

_________________
Purushotham Podaralla


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