-->
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.  [ 3 posts ] 
Author Message
 Post subject: Cached query result is not invalidated by entity update
PostPosted: Tue Nov 10, 2009 7:17 am 
Newbie

Joined: Wed Sep 09, 2009 8:49 am
Posts: 3
Hi,

I'm using entity inheritance with the interface trick to avoid ClassCastException. I have the following classes:

Code:
public interface AbstractNode {...}
public interface Advice extends AbstractNode {...}

@Entity
@Table(name = "node")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type")
@org.hibernate.annotations.Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE)
public abstract class AbstractNodeImpl implements AbstractNode, Serializable {...}

@Entity
@org.hibernate.annotations.Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE)
public class AdviceImpl extends AbstractNodeImpl implements Advice, Serializable {...}

I execute this query:

Code:
AbstractNode result = (AbstractNode) sessionFactory.getCurrentSession().createQuery("from Advice n where n.name = :name")
.setParameter("name", name)
.setCacheable(true)
.uniqueResult();


First time, the result is put in cache. The problem is that if I update the name of the Advice entity, the query cache is not invalidated and I still get the old result!

I guess this has something to do with the inheritance and/or the use of interfaces but I can't find a solution.

I'm using Hibernate 3.3.2.GA, Hibernate annotations 3.4.0.GA and EHCache 1.6.2.

Any idea?

Thanks.


Top
 Profile  
 
 Post subject: Re: Cached query result is not invalidated by entity update
PostPosted: Tue Nov 10, 2009 7:25 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
The query cache is not invalidated automatically just because you change a field of an entity. You have to invalidate it manually.
Maybe you should not cache the query if the data you retrieve is likely to change.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: Cached query result is not invalidated by entity update
PostPosted: Tue Nov 10, 2009 1:17 pm 
Newbie

Joined: Wed Sep 09, 2009 8:49 am
Posts: 3
hum, I wasn't aware of this behaviour. Thanks!


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