-->
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.  [ 1 post ] 
Author Message
 Post subject: Get n:1 Childs from n:m Child Set
PostPosted: Fri May 25, 2012 4:36 am 
Newbie

Joined: Fri May 25, 2012 3:46 am
Posts: 1
Hi, i search a neat solution for the following requirement.
Code:
@Entity
UserIdentity {
    ...
}
@Entity
TrainerIdentity {
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    UserIdentity getUserIdentity()
    ...
}
@Entity
SportsTeam {
    @ManyToMany(fetch = FetchType.LAZY)
    Set<TrainerIdentity> getTrainerIdentity()
    ....
    Set<UserIdentity> getTrainerUserIdentity() // <----- how?
}

the simplest solution:
Code:
SportsTeam {
    ...
    @Transient
    Set<UserIdentity> getTrainerUserIdentity() {
        Set<UserIdentity> result = new HashSet<UserIdentity>();
        Set<TrainerIdentity> holder = getTrainerIdentity();
        for (TrainerIdentity trainerIdentity : holder) {
            result.add(trainerIdentity.getUserIdentity());
        }
        return result;
     }
}

but this solution is very ugly: 1.) unnecessary data loading 2.) breaks persistence chain, therefore i get json serialization troubles with lazy UserIdentity childs!

what is the best solution for this use case?

i work with hibernate 3.6.10, JPA 2.0, use EntityManager and EclipseLink for typesafe criteria queries.
thanks!


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

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.