-->
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: criteria query using joins and unidirectional associations
PostPosted: Wed Jan 19, 2011 5:33 am 
Newbie

Joined: Wed Jan 19, 2011 5:00 am
Posts: 1
Hi,
we use criteria queries in conjunction with our generic backend so each DAO has its set of extra criteria queries for making complex searches. there i stumbled across the following problem:

given 2 classes: PriceModel and PriceListItem

class PriceModel{

@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private Set<GPCPriceListItem> items = new HashSet<GPCPriceListItem>();
}

The association is a uni-direction OneToMany from PriceModel to PriceListItem using the collection "items".
Due to the uni-directional behavior it is not possible to navigate from PriceListItem back to PriceModel (there is NO ManyToOne attribute like "model" in PriceListItem referencing the PriceModel) so the question is how i can i achieve something like the following query using criteria queries inside the PriceListItemDAO when searching for priceListItems.

query:
select pli.* from price_list_item pli, price_model_items pmi, price_model pm
where pli.id=pmi.items
and pmi.gpcprice_model=pm.id
and pm.since_valid_date<'2011-01-18'
and pm.until_valid_date>'2011-01-18';

i tried something like this but of course the property could not be resolved:

// creates a criteria for PriceListItem inside the DAO like createCriteria(PriceListItem.class)
final Criteria criteria = this.createCriteria();
// well there is no association path but how can i simply join two tables using criteria queries when there is only a unidirectional association from the "other" class?
criteria.createAlias("PriceModel.items", "pm");
criteria.add(Restrictions.le("pm.sinceValidDate", searchCriteria.getOrderDate()));
criteria.add(Restrictions.disjunction().add(Restrictions.ge("pm.untilValidDate", searchCriteria.getOrderDate())).add(Restrictions.isNull("pm.untilValidDate")));

thx
bernd


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.