-->
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: org.hibernate.LazyInitializationException
PostPosted: Thu Sep 18, 2008 1:58 pm 
Beginner
Beginner

Joined: Mon Jul 07, 2008 8:07 pm
Posts: 42
Hi,
I'm using Spring and Hibernate together via the HibernateDaoSupport class an an AnnotatedSessionFactoryBean. I'm using Spring 2.08 and Hibernate 3.2+.
I have a class that contains a collection of strings defined as so:

Code:
@CollectionOfElements(targetElement = String.class)
private List members = new ArrayList();


When I try to append to this collection at runtime, I get a org.hibernate.LazyInitializationException which states "failed to lazily initialize a collection of role: com.package.data.ChatRoom.members, no session or session was closed" What can I do to fix this? Do I need strict generic typing if I'm going to use a List?

- TK

Here's my update code:
Code:
@SuppressWarnings(value="unchecked")
   @Override public void appendMemberToRoom(Integer roomId, String userName) {
      ChatRoom room = (ChatRoom) this.getHibernateTemplate().get(ChatRoom.class, roomId);
      if (room.getMembers().contains(userName)) {
         
      } else {
         room.getMembers().add(userName);
         try {
         this.getHibernateTemplate().update(room);
         } catch (Exception e) {
            e.printStackTrace();
         }
      }
   }


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 5:48 pm 
Beginner
Beginner

Joined: Mon Jul 07, 2008 8:07 pm
Posts: 42
Found a workaround:
Code:
@CollectionOfElements (targetElement = String.class, fetch = EAGER)


However, I'm sometimes getting infinite thread loops when grabbing data from Hibernate. I make a call from my client, no error is thrown, the thread just hangs and I get no result. The only way I have fixed this is in restarting my server.

Any thoughts?

- TK


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.