-->
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: Session.refresh() does not fetch correct values
PostPosted: Mon Feb 05, 2007 8:33 am 
Newbie

Joined: Mon Jan 22, 2007 3:45 pm
Posts: 9
Hi,

I have a strange problem:

The Session.refresh() method does not refresh with the correct values from DB. In the log output I see that the correct SQL-Statements are generated but the returned values are not correct.

When I replace the refresh() statement with get(), the correct values are returned, but then I get a new persistent instance.
I tried Session.clear(), to ensure that there is no caching issue, but that had no effect.

Regards,
Markus


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 06, 2007 12:21 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi baeurlem

session get method gets the object from session if it not found in session then it will go for DB search. So when you are searching by get you are getting value .Try flush after save update delete .will solve your problem.

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 06, 2007 7:16 am 
Newbie

Joined: Mon Jan 22, 2007 3:45 pm
Posts: 9
Thank you for your reply,

I use hibernate with spring and HibernateTransactionManager. The session is flushed after each transaction (I can see it in the log output), so that cannot be the problem.

What does refresh() acually do? Does it fetch always from DB, or is there a cache in between? Does it fetch all associated non-lazy objects/collections? I think it does, but I'm not sure anymore.

I configured a second level cache (EhCache), but not for this class, which has the problem. Also I use the c3p0 connection pool

Regards, Markus


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 06, 2007 8:11 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
hi Markus

i think The session is flushed after end of transaction by HibernateTransactionManager.Might be you are not getting between data

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject: Same problem, possible bug within refresh cascading?
PostPosted: Fri Feb 09, 2007 1:33 pm 
Newbie

Joined: Mon Dec 12, 2005 4:25 am
Posts: 6
I have the same problem. Scenario is this:

Parent (1) -> Children (2) -> ChildrensChildren (5)

Relations are mapped with cascade="all-delete-orphan". Numbers in parentesis are the object count (and row count i DB).

Doing a session.refresh(Parent) generates one SQL statement that fetches data for all three entities from DB thus returning 5 rows. However, only the two first entities (Parent and Children) are expected which makes the Children collection contain 5 and not the expected 2 entities. One or both "Children" objects will be duplicated.

The problem has to do with an optimization that the refresh event is using to fetch all data in just one SQL statement. I don't know how to fix the optimization but it can be disabled by commenting line 122 in DefaultRefreshEventListener.

Code:
String previousFetchProfile = source.getFetchProfile();
// source.setFetchProfile("refresh");
Object result = persister.load( id, object, event.getLockMode(), source );
source.setFetchProfile(previousFetchProfile);


You can also avoid the problem by turing of refresh cascading in your mapping.

Hopefully Gavin will fix the true problem within the optimization, it has something to do with the class CascadeEntityLoader which i don't understand.

Third option is to evict your object from all caches and then reload it. Doing a session.load or session.get will fetch a correctly loaded entity. This does however require that the object is not loaded somewhere else within the session so you get two active instances of the same entity. This is a risky approach that can be usefull in some cases.

Has anyone seen a Jira issue on this? More threads on the forum?


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.