-->
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.  [ 2 posts ] 
Author Message
 Post subject: Define Disjunction on multiple associations with Criteria?
PostPosted: Sun Mar 14, 2010 5:08 am 
Newbie

Joined: Sun Mar 14, 2010 4:31 am
Posts: 1
Hi

I am creating a search query consisting of multiple associations. I need OR for all fields, I am able to define OR on fields with in an association. But I would also like to define OR on all associations also. Below is the code I am using currently:

Code:
Criteria customerCriteria = this.getSession().createCriteria(Customer.class);
Criteria contactsCriteria = customerCriteria.createCriteria("contacts");
Criteria ordersCriteria = customerCriteria.createCriteria("orders");
      
customerCriteria
   .add(Restrictions.disjunction()
      .add(Restrictions.like("email", "tony123@yahoo.com"))
      .add(Restrictions.like("pk", new IntegerPk("customer", "2"))));
      
contactsCriteria
   .add(Restrictions.disjunction()
      .add(Restrictions.like("email", "tony456@gmail.com"))
      .add(Restrictions.like("phone1", "7079845675"))
      .add(Restrictions.like("person.firstName", "Test First Name").ignoreCase())
      .add(Restrictions.like("person.lastName", "Test Last Name").ignoreCase())
      .add(Restrictions.like("address.postalCode", "94952", MatchMode.ANYWHERE)));
      
ordersCriteria
   .add(Restrictions.like("pk", new IntegerPk("order", "1")));
      
List<ICustomer> customerList = customerCriteria.list();


User can enter "email" defined in Customer Criteria, "First Name" defined in Contacts Criteria and "Order PK" defined in Order Criteria. What I need is OR between all associations.

Apart from OR, It would be very helpful if some one can give "Query By Example" alternative of this.

Thanks in advance


Top
 Profile  
 
 Post subject: Re: Define Disjunction on multiple associations with Criteria?
PostPosted: Wed Apr 14, 2010 3:32 pm 
Newbie

Joined: Thu Oct 07, 2004 3:53 pm
Posts: 10
Anybody? I'd really love to be able to do this as well.


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