-->
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: Purpose of many-to-many mapping - how to get the HashSet
PostPosted: Thu May 24, 2007 12:47 pm 
Beginner
Beginner

Joined: Wed May 23, 2007 1:07 pm
Posts: 28
Being quite new to Hibernate, I want to get some help on the concept of many-to-many associations and how to retrieve the HashSet.

If I have a many-to-many association between a User and a Role, how can I retrieve the HashSet of Roles of a specific User?

In User, I have

Code:
private Set roles = new HashSet();


And to get it I perform

Code:
java.util.Set set = userSacado.getRoles();


But if I try to
Code:
(HashSet)set;
it, it will give the exception

Code:
java.lang.ClassCastException: org.hibernate.collection.PersistentSet


Can anyone help me out on these concepts of (un)initialized collections and how can I get the HashSet (and its contents) available after I close the session, in my business and web tier of the application?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 1:21 pm 
Beginner
Beginner

Joined: Wed May 23, 2007 1:07 pm
Posts: 28
In other words, what I'm trying to know is if this way of accessing the HashSet is the best way if I want a collection of all the Roles associated with a user, that I can manipulate outside of the Hibernate and database context.


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.