-->
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.  [ 7 posts ] 
Author Message
 Post subject: question about saveOrUpdate and collections...
PostPosted: Mon Sep 29, 2003 11:48 am 
Beginner
Beginner

Joined: Fri Sep 05, 2003 10:17 am
Posts: 42
This question revolves around using saveOrUpdate() to save a 'child' or the 'many' of a one-to-many relationship. The collection definition in the 'parent' mapping file:

Code:
<set name="programs" cascade="delete" lazy="true">
      <key column="campaign_id"/>
      <one-to-many class="com.cportfolios.dao.Program"/>
</set>


The issue is this; i get a Program object and update an attribute via a setter method and saveOrUpdate the Program object. If i make the change in one browser i can see the change, but if i am viewing the same Program in a second browser i cannot see the updated data (yes i do a refresh on the browser... which a session.find() on the object). So why is it that if i make a change in one browser, i cannot see the change in a second browser? Where is the best first place to look to solve this problem?

Thank you for for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 29, 2003 12:16 pm 
Regular
Regular

Joined: Mon Sep 08, 2003 4:53 am
Posts: 70
Location: Germany
Do you:

- flush() the session (session.flush();)?
- commit() the session (session.connection.commit();)?
- use the same Hibernate session in the different browsers?
- use different Hibernate sessions in the diffenent browsers?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 29, 2003 12:25 pm 
Beginner
Beginner

Joined: Fri Sep 05, 2003 10:17 am
Posts: 42
the business end of the saveOrUpdate looks like this:

Code:
ses.saveOrUpdate( obj );         
ses.flush();
ses.connection().commit();


the second browser is using its own threadlocal session, so there are 2 different session references managed by the threadlocal.

Thank you and let me know.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 29, 2003 12:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Don't use long-lived sessions. A session lifespan usually is the same as a request.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 29, 2003 12:55 pm 
Beginner
Beginner

Joined: Fri Sep 05, 2003 10:17 am
Posts: 42
i am using the open-session-in-view pattern. i have an ActionFilter that exposes a static getConnection() method. I open the connection in my Struts Action class, save the data in a 'DAO' layer (pass the session as a param), and the session should be closing in the finally block of my ActionFilter.

ActionFilter
Code:
// in doFilter() method
try
{
   chain.doFilter( request, response );
}
finally
{
   try
   {
      HibernateSession.closeSession();
   }
   catch( Exception e )
   {
      log.error( "Error closing database connection.", e );
      e.printStackTrace();
   }
} //end doFilter

public static Session getConnection() throws Exception
{
   return HibernateSession.currentSession();
}


Struts 'Action' class
Code:
Campaign cmp = dm.getCampaign( frm.getCampaignId(), ActionFilter.getConnection() );


And in the DAO class...
Code:
ses.saveOrUpdate( obj );
ses.flush();
ses.connection().commit();


if i am am implementing the pattern correctly i should be opening and closing sessions properly. What do you think.

thanks again.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 29, 2003 2:28 pm 
Beginner
Beginner

Joined: Fri Sep 05, 2003 10:17 am
Posts: 42
just as another thought, it seems like my sessions are not being closed in the ActionFilter. do i need to explicitially close the sessions within my Struts Action classes? My Java memory footprint grows at a rather large rate and i am suspect of the sessions and the open-session-in-view pattern. any and all thoughts are appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 29, 2003 4:54 pm 
Beginner
Beginner

Joined: Fri Sep 05, 2003 10:17 am
Posts: 42
I added debug statements to watch the sessions open and close from within the app and am happy to report they are opening and closing as i would expect and the open-session-in-view pattern is operating.

I am however having issues with the JVM and the memory footprint. I easily 'spool' up to 113M for an app that is still in development and does not have much data in the database. But this is another topic and thread all together.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.