Hi!
I'm in the problem in many-to-many relation beacause Hibernate return's too many object instances
I have 3 tables mapped as:
Code:
<class name="Ankeet" table="ankeet" lazy="false">
<id name="id" column="id" type="long" >
<generator class="sequence">
<param name="sequence">seq_ankeet</param>
</generator>
</id>
<property name="name" type="java.lang.String" column="name" />
<bag name="tegevusedList" table="ankeet_tegevus_aspekt">
<key column="ankeet" />
<many-to-many class="Tegevus" column="tegevus"/>
</bag>
<bag name="apektList" table="ankeet_tegevus_aspekt">
<key column="ankeet" />
<many-to-many class="Aspekt" column="aspekt"/>
</bag>
</class>
<class name="Tegevus" table="tegevus" lazy="false">
<id name="id" column="id" type="long" >
<generator class="sequence">
<param name="sequence">seq_tegevus</param>
</generator>
</id>
<property name="name" type="java.lang.String" column="name" />
<bag name="ankeedidList" table="ankeet_tegevus_aspekt">
<key column="tegevus"/>
<many-to-many class="Ankeet" column="ankeet"/>
</bag>
<bag name="aspektList" table="ankeet_tegevus_aspekt">
<key column="tegevus" />
<many-to-many class="Aspekt" column="aspekt"/>
</bag>
</class>
<class name="Aspekt" table="aspekt" lazy="false">
<id name="id" column="id" type="long" >
<generator class="sequence">
<param name="sequence">seq_aspekt</param>
</generator>
</id>
<property name="name" type="java.lang.String" column="name" />
<bag name="ankeetList" table="ankeet_tegevus_aspekt">
<key column="aspekt"/>
<many-to-many class="Ankeet"/>
</bag>
<bag name="tegevusList" table="ankeet_tegevus_aspekt">
<key column="tegevus"/>
<many-to-many class="Tegevus"/>
</bag>
</class>
So every table has many to many relations to each other
and are bound together in one table ankeet_tegevus_aspekt
And in ankeet_tegevus_aspekt table there is data like this:
Code:
Aspekt |Ankeet |Tegevus
8 |116 |11
9 |116 |11
8 |116 |12
By loading the ankeet there is
3 instances of tegevus not 2
Ankeet[0] (tegevus count(3))
- Tegevus (id:11)
- Tegevus (id:11)
- Tegevus (id:12)
How should I write the query that ankeet instance would group it's tegevus data, that I could get the result like
Ankeet[0] (tegevus count(2))
- Tegevus (id:11)
- Tegevus (id:12)[/code][/list]