• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session.refresh and objects in my HttpSession

 
Andy Westley
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

This might be a really stupid questions, but its getting late here and I'm probably missing something obvious. I'm pretty new to hibernate, but the speed with which I've got my new webapp going is frightening - maybe that's the problem - I'm skipping along without getting all the details.

I'm writing a fairly simple MVC webapp. User logs in, user object retrieved from database and stored in HttpSession object. First page of app displays a list of activities stored in user object contains list of activities.

Functionality I've written currently happily adds a new activity directly to the database with a foreign key back to the logged in user.

However whenever I access the user object from HttpSession object, it's collection of activities never includes newly added activities. If I restart the app, or kill my session and log in again, the user object happily lists all the original + new activities.

Am I missing something hibernatey, or is the a fatal flaw in the design of my app?

I'm not actively putting the activity object into the collection of activities in the existing user object and then saving that. Instead, I'm creating a new activity, and adding the user object to it. Is that my problem? Should I be updating the user, rather than directly adding the activity?

After a quick google, I tried adding session.refresh to the end of the saveOrUpdate method of my GenericDAO, but that's done nothing.

Any help for a frazzled brain?
 
Andy Westley
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One solution I guess is to not hold the user object in my HttpSession, but some other sort of ctx object that I create based on the user object. That way when I need to get the activities I need to get the user again, but have the id readily available.

I'm sure that would work, but is it the right way to do thing?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic