Hibernate version:3.2.4.sp1
Hello !
I've got the following objects relations :
[Product]1--*[Price]*--1[company]
So one price per company for one product.
The Product object contains a set of prices, here are some relevant parts of code :
Product class :
Code:
public class Product{
private int id;
....
private Set<Price> prices;
....
}
Product's prices set mapping :
Code:
<set name="prices" fetch="join" lazy="false">
<key column="product_id"/>
<one-to-many class="Price"/>
</set>
If I run the following HQL request, everything goes all right (I get only one item in the "prices" set and it's fetched with the first request) :
Code:
FROM Product AS product JOIN FETCH product.prices AS price WHERE product.id=56688000 AND price.company.id=10022
On the other hand I cannot reproduce the behaviour with the criteria API ; here is how I translated the request :
Code:
Criteria productCriteria=session.createCriteria(Product.class);
productCriteria.add(Restrictions.idEq(56688000));
productCriteria.setFetchMode("prices", FetchMode.JOIN);
Criteria priceCriteria=productCriteria.createCriteria("prices", JoinFragment.INNER_JOIN);
priceCriteria.add(Restrictions.eq("company.id",10022));
List<Product> products=(List<Product>)priceCriteria.list();
In that case, a second SQL request is run to fech the prices set and it contains all the prices for all the companies (for the current product), so it seems that my criterias on "prices" are ignored.
Is that a bug or I'm I doing something wrong ?