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?