-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Selecting across multiple joins with collections
PostPosted: Tue Jun 02, 2009 3:28 am 
Newbie

Joined: Tue Jun 02, 2009 3:25 am
Posts: 1
'm having trouble getting a hibernate select to return a correctly populated object graph, when the select contains joins across many collections.

Eg:

Code:
        String sql = "select distinct changeset " +
                        "from Changeset changeset " +
                        "join fetch changeset.changeEntries as changeEntry " +
                        "join fetch changeEntry.repositoryEntity as repositoryEntity " +
                        "join fetch repositoryEntity.repository as repository " +
                        "where repository.connectionName = :connectionName";


A Changeset has many ChangeEntries
A ChangeEntry has one RepositoryEntity
A RepositoryEntity has one Repository
The above statement returns the correct data, but the object graph is not correctly populated -- ie., each Changeset contains every ChangeEntry, not just it's own children.

Here's the relevant snippets of those two classes:

Code:
public class Changeset {

    @NotNull
    @OneToMany(mappedBy="changeset", targetEntity=ChangeEntry.class, cascade={CascadeType.ALL }, fetch=FetchType.EAGER )
    private Set<IChangeEntry> changeEntries;

And...

Code:
public class ChangeEntry extends BaseEntity implements IChangeEntry {

    @NotNull
    @ManyToOne(targetEntity=RepositoryEntity.class, cascade=CascadeType.ALL,fetch=FetchType.EAGER)
    @ForeignKey(name="FkChangeEntryRepoEntity")
    private IRepositoryEntity repositoryEntity;

Any assistance is greatly appreciated

Regards

Marty


Top
 Profile  
 
 Post subject: Re: Selecting across multiple joins with collections
PostPosted: Tue Jun 02, 2009 4:28 am 
Newbie

Joined: Thu Jan 13, 2005 4:04 am
Posts: 12
Location: Estonia
Hi,

Try using session.createQuery("your query").setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)

Ilhan


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.