I'm having problem retrieving parent data with one-to-many relationship. Whenever i retrieve parents with more than one child, the list returned contains duplicate parent records, although the physical records in database is unique
The parent record has one ScoreCard
The child records have two TestChunk
Code:
String scoreCardQuery = "select s from ScoreCard as s left join fetch s.testChunks where s.reviewer.id = :reviewerPKID";
Query query = session.createQuery(scoreCardQuery);
query.setString("reviewerPKID",reviewer.getId());
scoreCardList = query.list();
This returns two identical ScoreCard objects.
The mapping for ScoreCard is:
Code:
<!-- Childrens here -->
<bag name="testChunks" fetch="join" cascade="all,delete-orphan">
<key>
<column name="scoreCardPKID"/>
</key>
<one-to-many class="TestChunk"
not-found="ignore"/>
</bag>
The mapping for TestChunk is:
Code:
<!-- Parents here -->
<many-to-one name="scoreCard" class="ScoreCard"
not-null="true"
lazy="false" unique-key="uniqueChunk">
<column name="scoreCardPKID"/>
</many-to-one>
Please help me make the list return unique ScoreCard records only.
Any help would be appreciated with credit.
Kind regards,
Roy