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
|