-->
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: Problem with filtering the select statement.
PostPosted: Wed Nov 11, 2009 10:21 am 
Newbie

Joined: Sat Nov 07, 2009 12:08 pm
Posts: 3
I have ManyToOne relationship which one table linking multiple entity.

Example Shop (Animal Shop) which only sell Cat and Dog:

Shop
-shopId
-shopCode
Cat
-catId ---------catId
-catName
-catType
Dog
-dogId----------dogId
-dogName
-dogType

Linking relationships Are
1. Shop ManyToOne Cat
2. Shop ManyToOne Dog


Below Is the Code for Searching with filtering criteria.

Code:

public List<Shop>searchByShop (QueryRequest<Shop> query){

Shop example = query.getExample();

DetachedCriteria criteria = DetachedCriteria.forClass(Shop.class);
//Filtering
// Check not null or empty
criteria.add(Restrictions.eq("shopCode", example.getShopCode()));

// Check not null or empty
criteria.createCriteria("cat")
.add(Restrictions.ilike("catName", example.getCat().getCatName());
.add(Restrictions.ilike("catType", example.getCat().getCatType());

// Check not null or empty
criteria.createCriteria("dog")
.add(Restrictions.ilike("dogName", example.getDog().getDogName());
.add(Restrictions.ilike("dogType", example.getDog().getDogType());

return getHibernateTemplate().findByCriteria(criteria);
}



The Problem above code is this line:
Quote:

//Included from search
// Check not null or empty
criteria.createCriteria("cat")
.add(Restrictions.ilike("catName", example.getCat().getCatName());
.add(Restrictions.ilike("catType", example.getCat().getCatType());

//Excluded from search
// Check not null or empty
criteria.createCriteria("dog")
.add(Restrictions.ilike("dogName", example.getDog().getDogName());
.add(Restrictions.ilike("dogType", example.getDog().getDogType());



When you enter catName and catType for search ,it works accordingly. [ First come first server ]
When you enter catName , catType, dogName and dogType for search, it will output everything.( without filter)

May I know how to solve this problem?
Which library or method I should call appropriately?

Thanks


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.