-->
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: How to create a PersistentSet
PostPosted: Wed Jul 29, 2009 10:01 pm 
Newbie

Joined: Thu Jul 23, 2009 11:48 am
Posts: 9
Hello Hibernate gurus! I'm just getting started with Hibernate and am having trouble with the <set> attribute. I have a User class that has a PersistentSet called "roles", like so:
Code:
User.java
*********
public class User {
  PersistentSet roles;
  //...getter & setter
}

User.hbm.xml
************
<class name="BasicUser" table="users">
    <set name="roles" table="roles">
         <key column="user_id"/>
         <element type="java.lang.String" column="user_role"/>
    </set>
</class>

The problem is that when I try to create and save a user, I get a "org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed" exception. Here's the relevant code:
Code:
BasicUser basicUser = new BasicUser();
PersistentSet roles = new PersistentSet();
roles.add(Roles.USER);
basicUser.setRoles(roles);
basicUserDao.save(basicUser);

The exception is thrown at line 3, "roles.add(Roles.USER);". That seems like a really weird place to throw an error, so I presume I'm not instantiating PersistentSet correctly. The other constructors involve a SessionImplementor, but I can't find any documentation on where the SessionImplementor should come from. Any suggestions? Am I going about this entirely the wrong way? Thanks in advance!

Dane


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.