-->
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: Eagerly fetching one side of a ManyToMany
PostPosted: Thu May 28, 2009 7:06 pm 
Beginner
Beginner

Joined: Mon Jul 07, 2008 8:07 pm
Posts: 42
First of all, THANK YOU FOR REMOVING THE CREDITS SYSTEM ON THE FORUM! Thank you thank you thank you...

I'm using the latest GA of Hibernate Core, Hibernate Annotations, etc. and I need to know if this is possible. I need to eagerly fetch one side of a many to many relationship. I am using Hibernate to persist objects which are written to a byte stream after the session is closed, so I need to make sure that this association fetches only the first level of associated entities.

I have a Group object many User objects which belong to many Groups. My JoinTable is mapped in my Group class like so:
Code:
   @ManyToMany(targetEntity=User.class)
   @JoinTable (
      name="m2m_group_members",
      joinColumns=@JoinColumn(name="group_id"),
      inverseJoinColumns=@JoinColumn(name="user_id")
   )         
   private List<User> members = new ArrayList<User>();

And on the other side in the User class, they are mapped like so:
Code:
   @ManyToMany(mappedBy="members",
      targetEntity=Group.class)
   private List<Group> groups = new ArrayList<Group>();


What I'd like to do is have my Group's member property be eagerly fetched, but not fetch the subsequent groups of the users. Is this at all possible in the current version of Hibernate?

Is there something else I can do to initialize the first level of the collection?


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.