-->
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.  [ 5 posts ] 
Author Message
 Post subject: Refreshing Objects in Session
PostPosted: Wed Oct 19, 2011 11:22 am 
Newbie

Joined: Wed Oct 19, 2011 11:10 am
Posts: 3
Hi,
I have a login page and once the user is logged in i will add the user object in the servlet session.
This user table has one to many relationships with many tables. One of the table is EmploymentDetails.
One user might have more than one entry in employment table.
When the user wants to see the employment details, he will be taken to the employment details page.
So in the controller, i will do the following before taking him to the jsp page.

Part of the code :

usersDAO.attachClean(user); // Here i am attaching the user to the hibernate session.

Set<EducationalDetails> educationDetailsSet = user.getEmploymentDetailses();

Once the user is taken to the jsp page,

if i refresh the page again, the query is not fired as the data is fetched from the Hibernate session.
But, some one else has modified the data in between directly in the table.
But these modified data are not reflected in the JSP page as it still fetch values from hibernate session.

How to prevent this?

If i need to add session.refresh(), Will it trigger the query every time when i refresh the page?
If it is so, how to improve the performance as it has to hit the DB every time?

The Set<EducationalDetails> was generated by a tool. Can i modify it to List as i want the insertion order in the JSP?


Thanks,
Baskar.S


Top
 Profile  
 
 Post subject: Re: Refreshing Objects in Session
PostPosted: Wed Oct 19, 2011 11:43 am 
Newbie

Joined: Tue May 24, 2011 3:23 pm
Posts: 6
Quote:
if i refresh the page again, the query is not fired as the data is fetched from the Hibernate session.
But, some one else has modified the data in between directly in the table.
But these modified data are not reflected in the JSP page as it still fetch values from hibernate session.

How to prevent this?


Is another application interacting with the database and modifying data? Perhaps you can avoid modifying the data except through Hibernate so that any changes to the data are visible to Hibernate.

Quote:
The Set<EducationalDetails> was generated by a tool. Can i modify it to List as i want the insertion order in the JSP?


Hibernate won't care if the EducationDetails is a list or a set, it'll handle either one, so you should have any trouble changing the collection type as far as it's concerned.


Top
 Profile  
 
 Post subject: Re: Refreshing Objects in Session
PostPosted: Wed Oct 19, 2011 11:55 am 
Newbie

Joined: Wed Oct 19, 2011 11:10 am
Posts: 3
Thanks for your reply.

Sometimes database administrator may change certain fields directly in database.
And we also use schedulers that runs at specified intervals and modifies certain values.


Top
 Profile  
 
 Post subject: Re: Refreshing Objects in Session
PostPosted: Wed Oct 19, 2011 11:59 am 
Newbie

Joined: Tue May 24, 2011 3:23 pm
Posts: 6
If the scheduler can be run in the Java code through hibernate, that'll fix that problem. Same thing with the admin, if they can use a tool that goes through hibernate to modify the entities.


Top
 Profile  
 
 Post subject: Re: Refreshing Objects in Session
PostPosted: Wed Oct 19, 2011 12:02 pm 
Newbie

Joined: Wed Oct 19, 2011 11:10 am
Posts: 3
Thats great.
But still i am curious to know, How to handle if administrator changes data directly?


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