-->
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.  [ 2 posts ] 
Author Message
 Post subject: Stale data with long running session
PostPosted: Tue Jun 06, 2006 4:54 pm 
Newbie

Joined: Wed Mar 22, 2006 3:22 pm
Posts: 9
Hibernate version:
3
Mapping documents:
NA
Code between sessionFactory.openSession() and session.close():
NA
Full stack trace of any exception that occurs:
NA
Name and version of the database you are using:
NA
The generated SQL (show_sql=true):
NA
Debug level Hibernate log excerpt:
NA

I am using hibernate within a web application. The requirements state that I must use the users Oracle account when creating a JDBC connection. This of course means I cannot use connection pooling right? So, this also means I must use long running sessions. When the user logs in I create a JDBC connection and assign it to a Hibernate Session. The user will use this session throughout the life of thier application session. Currently we are having problems where user A retrieves data and so this data is loaded into the first level cache. User B does the same thing but edits and saves the changes back to the database. User A then retrieves the data again but the changes user B made are not reflected in the HTML. I think I know but do not know how to solve the problem. The reason user A does not see the changes is becuase the first level cache is stale. How do I update the first level cache? I tried the following but it gave me a null pointer exception..


ret = session.get(class, id)
session.refresh(ret);

I am not sure how to proceed. Is their a better way to handle the sessioning? Or is their a way to refresh the cached entity?

thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 06, 2006 5:37 pm 
Senior
Senior

Joined: Tue Mar 09, 2004 2:38 pm
Posts: 141
Location: Lowell, MA USA
Reusing a session like that isn't the best idea. A better approach would be to use a user supplied connection. You can do this by defining the following property in your hibernate.cfg.xml:

Code:
<property name="hibernate.connection.provider_class">
org.hibernate.connection.UserSuppliedConnectionProvider
</property>


Then when you go get your new Session:

Code:
Connection conn = (get your JDBC connection here);
Session session = sessionFactory.openSession(conn);
...


You can probably package this up nicer with a utility class. But by doing this, you won't have your stale data issue.

Ryan-

_________________
Ryan J. McDonough
http://damnhandy.com

Please remember to rate!


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