-->
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: Initialising a lazy collection
PostPosted: Wed Nov 11, 2009 6:07 pm 
Newbie

Joined: Wed Nov 11, 2009 5:54 pm
Posts: 2
My association is bi-directional meaning i can add a new group msg by either saving the message itself or adding the msg to the msg list of the group it belongs and then updating the group in the database and the code for both approaches if below

public void saveGroupMessage(GroupMessage groupMessage) throws Exception {
getHibernateTemplate().save(groupMessage);
getHibernateTemplate().refresh(group);
}

OR

public void saveGroupMessage(GroupMessage groupMessage, UserGroup group) throws Exception {

List<GroupMessage> msgs = group.getGroupMessages();
msgs.add(groupMessage);
group.setGroupMessages(msgs);
getHibernateTemplate().update(group);
getHibernateTemplate().refresh(group);

}

The reason i call group.setGroupMessages(msgs) is because the parameter am passing is a list of msgs includiing a newly added msg.
By the way, the msg gets saved in the database coz i see it there, and everything works fine when this collection is not set to lazy, the problem only shows up when i set it to lazy, then i try to call Hibernate.initialise(Object) manually(With a new session), the list of msgs gets initialised but never includes the newly added msg even though it actually exists in the database, unless i restart the web server. Am realising that spring's hibernate templete class is the problem, because if i look up the list of msgs when managing my own hibernate session, the new msg shows up, is think i have to find a way of synhronizing spring's hibernateTemplate with the new session i created when intialiaising the lazy collection or with the database itself, what do u think guys?
I appreciate any help.


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.