I looked around thinking this is answered somewhere but didn't find anything......
I'm using Hibernate 2.0.2. I'm creating the following HQL:
Code:
List ads = session.createQuery("select distinct ad from com.itsolut.entity.tracker.Ad as ad " +
" left join fetch ad.redirects").list();
In the database to test, I have two Ads and 3 Redirects.
A1 links to R1 & R2
A2 links to R3
When I issue the above query A1 is returned twice (once for each Redirect record). Is this the expected functionality with the fetch keyword?
Because when I remove the fetch keyword, the query return A1 once liked I expected. Except now I have to manually initialize the collection before returing to the view....
Here are the mappings:
Code:
<class name="com.itsolut.entity.tracker.Ad" table="ad">
<id name="adID" type="long" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="companyID" type="int" not-null="true"/>
<property name="creation" type="timestamp"/>
<property name="start" type="date"/>
<property name="stop" type="date"/>
<property name="name" type="string"/>
<many-to-one name="lastRedirect" class="com.itsolut.entity.tracker.Redirect"/>
<set name="redirects" lazy="true" cascade="save-update">
<key column="adID"/>
<one-to-many class="com.itsolut.entity.tracker.Redirect"/>
</set>
</class>
<class name="com.itsolut.entity.tracker.Redirect" table="redirect">
<id name="redirectID" type="long" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="url" type="string"/>
<property name="creation" type="timestamp"/>
<property name="clicks" type="int"/>
<property name="sales" type="int"/>
<property name="revisit" type="int"/>
<property name="saleMoney" type="com.itsolut.core.hibernate.type.MoneyType">
<column name="saleAmount"/>
<column name="saleCurrency"/>
</property>
<property name="active" type="boolean"/>
<many-to-one name="ad" column="adID" class="com.itsolut.entity.tracker.Ad"/>
</class>