-->
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: Hibernate Criteria or HQL Query on unidirectional many to on
PostPosted: Sat Jan 21, 2012 10:58 am 
Newbie

Joined: Sat Jan 21, 2012 10:54 am
Posts: 2
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

Code:
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:
Code:
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)
Code:
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


Glad for any answers. How I can resolve this problem? Maybe bidirectional association?


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.