-->
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.  [ 7 posts ] 
Author Message
 Post subject: Second Level Caching and inserting new data
PostPosted: Thu Nov 29, 2007 4:09 pm 
Newbie

Joined: Thu Nov 29, 2007 4:06 pm
Posts: 1
I have this problem, where after doing an insert, my cache is not being updated with a new record.
However, updating existing row works fine.

Any ideas?


Top
 Profile  
 
 Post subject: Re: Second Level Caching and inserting new data
PostPosted: Thu Nov 29, 2007 4:27 pm 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
pajeczyca wrote:
I have this problem, where after doing an insert, my cache is not being updated with a new record.
However, updating existing row works fine.

Any ideas?


I think you have to set the CACHEMODE to update the second level cache or evict that entry from second level cache when it is updated. And when it is read after update, it is being added to cache.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 29, 2007 6:47 pm 
Newbie

Joined: Thu Nov 29, 2007 11:49 am
Posts: 7
I have the same problem and tried evicting the value but still does not seem to work. I also tried turning off all cache and this did not work either. Also, I saw this issue only when the version of hibernate was upgraded to 3.2.5

_________________
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 29, 2007 7:01 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
ayadav wrote:
I have the same problem and tried evicting the value but still does not seem to work. I also tried turning off all cache and this did not work either. Also, I saw this issue only when the version of hibernate was upgraded to 3.2.5


Explain more what your problem is. Evicting an entity which is going to be inserted does not make sense.


Top
 Profile  
 
 Post subject: Re: Second Level Caching and inserting new data
PostPosted: Thu Nov 29, 2007 7:04 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
pajeczyca wrote:
I have this problem, where after doing an insert, my cache is not being updated with a new record.
However, updating existing row works fine.

Any ideas?


Which cache are you using?
What is the cache settings for that entity?
Is the insert code running in a transaction scope? If so, have you linked hibernate and transaction manager?

The cache mode doesn't seem to help since you say updates are working unless you manually set the cache mode to something else during inserts.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 29, 2007 7:06 pm 
Newbie

Joined: Thu Nov 29, 2007 11:49 am
Posts: 7
Here is the code snippet.

Transaction transaction = null;
session.setFlushMode(FlushMode.NEVER);
transaction = this.session.beginTransaction();
transaction.begin();
session.saveOrUpdate(object);
this.session.flush();
if (transaction != null) {
transaction.commit();
}


session.evict(object)
closeSession();


open anther session.
session.list(query);
The list return a different result then what is in the database. The update is fine.
I am using EhCache. I tried various options like turning off query cache, second level cache etc. But no use. Also, like I said this problem happened when I upgraded to 3.2.5. Everthing was fine prior to that.

Thanks

_________________
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 29, 2007 7:51 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
ayadav wrote:
Here is the code snippet.

Transaction transaction = null;
session.setFlushMode(FlushMode.NEVER);
transaction = this.session.beginTransaction();
transaction.begin();
session.saveOrUpdate(object);
this.session.flush();
if (transaction != null) {
transaction.commit();
}


session.evict(object)
closeSession();


open anther session.
session.list(query);
The list return a different result then what is in the database. The update is fine.
I am using EhCache. I tried various options like turning off query cache, second level cache etc. But no use. Also, like I said this problem happened when I upgraded to 3.2.5. Everthing was fine prior to that.

Thanks



Something doesn't look right here. This is not a cache issue if you get the same results when you turn off caches. These are the things that come to my mind:

1- You are creating a new transaction which might be nested into an existing transaction and evicting the object before the outer transaction commits will discard the change (I am not very sure here but studying the code makes this clear).

2- Use a JDBC logger (p6spy) and see if your entity makes it to database.

3- Query cache checks update time stamp cache to see if it needs to throw away a currently cached query result. Make sure update stamp cache stays long enough for the second session.

4- Why don't you try this code as suggested in documentation?

Code:
Session sess = factory.openSession();
Transaction tx;
try {
     tx = sess.beginTransaction();
     //do some work
     ...
     tx.commit();
}
catch (Exception e) {
     if (tx!=null) tx.rollback();
     throw e;
}
finally {
     sess.close();
}


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