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();
}
}
}