-->
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: @Where clause on collection ignored when @Cache used
PostPosted: Fri Oct 24, 2008 2:53 pm 
Newbie

Joined: Fri Mar 09, 2007 2:01 am
Posts: 5
Hibernate version: Annotations 3.4.0.GA, core-3.3.1.GA


I've discovered that if I have a collection as such:
private List<Content> content;

in a class, and have it mapped as follows:

@OneToMany(mappedBy = "feed", fetch = FetchType.LAZY, cascade = javax.persistence.CascadeType.ALL)
@Cascade(CascadeType.DELETE_ORPHAN)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@OrderBy("displayOrder")
@Where(clause = "active = 1")
public List<Content> getContent() {
if (content == null){
content = new ArrayList<Content>();
}
return content;
}

The where clause is ignored when getting the items. If I remove the @Cache annotation, the where clause is honored. The same happens if I were to add a @LazyCollection(LazyCollectionOption.EXTRA) annotation.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2008 3:34 pm 
Newbie

Joined: Fri Mar 09, 2007 2:01 am
Posts: 5
Actually, I figured out why this is happening, still not sure the best way to get around it. But here's what's happening,

Collection initialized into cache with where clause, gives you 3 entries. In the code, you change one of the entries, setting active = false in the example above. Since I didn't actually change the collection, hibernate doesn't know to flush the cache, so the collection cache still returns the entry, even though active = false.

Thoughts on how to get around this?


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.