Dear users,
I would like to use subselect fetch mode to avoid a cartesian product during a Criteria query. I read informations about this problem in the "Java Persistence with Hibernate" book and I first thought i found the solution on page 588 (The cartesian product problem) but it finally seems it does not work as expected.
I'm trying to fetch informations as follow:
Code:
List<alert> alerts = session.createCriteria(Alert.class)
.createCriteria("sources")
.createCriteria("addresses")
.add(Expression.like("address", "10.192.%"))
.list();
In a DB structure where an alert contain a set of sources which could contain a set of addresses. Addresses are linked using an association table (N..N) as shown in the mapping below:
Code:
<class name="Alert" table="alert">
<set name="sources" table="source_instance" fetch="subselect">
<key column="_alert_oid" />
<one-to-many class="Source"/>
</set>
</class>
<class name="Source" table="source_instance">
<id name="oid" column="_oid" type="int" />
<property .. some properties .. />
<set name="addresses" table="address_association"
fetch="subselect">
<key column="_node_oid" />
<many-to-many column="_address_oid" class="Address"/>
</set>
</class>
<class name="Address" table="address">
<id name="oid" column="_oid" type="int" />
<property name="ident" column="ident" type="string" />
<property name="address" column="address" type="string" />
</class>
As said before, even with the fetch="subselect" mode activated I always retrieve the cartesian product of matched addresses. I mean that if i have 2 alerts into the DB, which both of them contains 2 addresses (1 alert contain 2 addresses), i always retrieve 4 alerts and not the 2 expected (alerts are built from the address without checking for distinct values)...
Any advise or tip is welcome !
Thanks in advance.
Joël