-->
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.  [ 4 posts ] 
Author Message
 Post subject: Suspect object caching even after session.clear()
PostPosted: Thu Jul 12, 2007 11:13 am 
Newbie

Joined: Thu Jul 12, 2007 10:58 am
Posts: 4
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

[b]Hibernate version:2.17[/b]


Hi guys:
I've encountered this problem, any help as to the cause of the problem and/or solutions will be greatly appreciated. I"m using Hibernate 2.17 by the way.

the actions sequence involves,

1. using hibernate hql query to select a list of objects. e.g. select * from tableA.

2. select one of the result object for modification, then call the session.update() function.

3. insert new object of the same type into the database with session.save() function.

4. now the "PROBLEM" I would call session.clear(), then carry out the same query as step 1. In the newly returned list includes the object which I inserted under step 3, as well as the object i updated in step 2. However, the modifications which I made to the object in step two is not shown, the old values are returned. When I conduct the exact same query again, the changes are then shown.


This to me seems like some sort of caching mechanism, but I thought the session.clear() call is suppose to take care of that possibility.

Has anyone came across similar situation???

Thanks heaps for the help, or just reading thru my question.


William


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 12, 2007 12:17 pm 
Newbie

Joined: Wed May 30, 2007 1:30 pm
Posts: 3
Location: Salt Lake City, UT
Can you clear up a couple of questions I have about your question:

1) When you say you do a select *, do you mean you're using projection in your HQL query (i.e. select colA, colB from TableC). Or are you simply saying that you're selecting all the objects froms the table (i.e. from TableC). It sounds like the latter, but I just wanted to make sure.

2) Are you using any type of caching in your application? Depending on your answer to that, have you explicitly turned off caching or are you just relying on the default behavior?

3) I may be missing something, but what is the purpose of calling session.clear()? Why do you want the first level session cache cleared out? Does the same thing happen without the session.clear()?

Sorry for a lot of questions and no answers.

-Nick-


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 12, 2007 9:54 pm 
Newbie

Joined: Thu Jul 12, 2007 10:58 am
Posts: 4
hi nick .. thanks for the help
to clarify things

1) By * i mean selecting all the data from that particular table.

2) I'm not doing any caching for my app, and I have specifically turned 2nd level caching off with the query.setCacheable(false)

3) The session.clear function is to clear the caching done by the hibernate session. Originally I did the app without calling this function and we experienced another sort of caching problem, the list of data entries returned are constantly outdated, i.e. newly added entries are not returned right away.
The session.clear() function fixed that problem.

Hopfully these answers help...

thanks heaps


William


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 24, 2007 5:17 am 
Newbie

Joined: Thu Jul 12, 2007 10:58 am
Posts: 4
I have finally got to the bottom of the problem.

This post is just a reference for any that might come across similar problem, tho the number seems few and rare by the amount of related posts i can find ...haha... anyway down to business.

To put everything in context, i'm trying to implement a paging function and which is done by creating a paging class that maintains a copy of the criteria created when the search is conducted the first time. First and max attributes are used on the criteria object to move to other pages while other parts of the criteria are unchanged.

Turns out, as I'm trying to update an entry in the database, the thread/session used is different from the session used to create the criteria.
Essentially i am using two sessions, one by the criteria to do the select statements, and one for all the other actions. When i do session.clear(), the new session( not the one used by criteria ) is cleared, but the session used by criteria is not cleared, leaving stale data in the session cached.

I hope this makes sense for anyone that comes across this problem, feel free to contact me if any clarification is needed.

All the above is based on Hibernate2 btw.... i'm sure such problem would not exist in hibernate3 with detachedcriteria!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.