-->
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: collections getting invalidated from cache for unknown reaso
PostPosted: Wed May 16, 2007 7:23 pm 
Newbie

Joined: Sat Nov 19, 2005 3:09 pm
Posts: 6
Hibernate version: 3.2.1
Using a mix of JPA and hibernate annotations.

Hi, I am trying to use 2nd level cache to cache a tree of entities and collections, but only certain collections appear to be caching correctly. I run a Query.list() that it loads the entities I asked for. Immediately after I use the Hibernate.initialize() to initialize the collecitons of the entities. I looked at the hibernate debug logs, and I can see when it goes to fetch the collections it does a cache miss, then loads the collection from the database, and says that it is loading the new collection into the cache. But then next time I run it, it does the exact same thing.

Looking through the logs I see these suspect lines:
18:22:45,519 dirty checking collections [AbstractFlushingEventListener]
18:22:45,519 Collection dirty: [com.mycompany.verification.persistent.User.transactions#1635] [CollectionEntry]
....

And these the collections that are not caching correctly so I'm reasoning that for some reason hibernate thinks the collections are dirty and invalidates them from the cache? Wouldn't a dirty collection though result in a sql update? And all that i run in the entire session is a Query.list() so I don't see how it could dirty itself in that one transaction. Could running Hibernate.initialize() on collections AND child collections of the entities in that collection cause some unknown problem? Any other way for the collections to get dirty?

Oh, and I even set the session.setReadOnly(true) to see if it would still happen and I still get the Collection dirty: ... in the logs.

I tried this with JbossCache and EhCache and I'm seeing the same behavior with both.

Any ideas? If there is anything you think that will help I will gladly post. There is tons of debug output and mappings so I will only post parts if someone has a hunch what it could be an it will help.
Thanks very much in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 17, 2007 9:17 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
are you changing any of the values on the way in? Hibernate keeps track of what it reads in from the database and what gets put in the object, and if they ever change the object is flagged as dirty.

Like, if you have any trimming or number rounding in a POJO setter or something.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 17, 2007 11:04 am 
Newbie

Joined: Sat Nov 19, 2005 3:09 pm
Posts: 6
Thanks for responding.

My entity isn't doing anything to the collection:

Code:
   @OneToMany(mappedBy = "user", cascade = { CascadeType.ALL })
   @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
   public Set<VerificationTransaction> getTransactions() {
      return transactions;
   }

   public void setTransactions(Set<VerificationTransaction> transactions) {
      this.transactions = transactions;
   }


and inside the session all that happens is this:

Code:
                query = .....;
                query.setReadOnly(true);
      List users = query.list();
      if (!count && !users.isEmpty()) {
         for (User user : (List<User>) users) {
            Hibernate.initialize(user.getTransactions());
            for(VerificationTransaction vt: user.getTransactions()){
               Hibernate.initialize(vt.getHistory());
            }
         }
      }


So you can see that i do initialize 2 nodes down the tree for each user. The initialized objects down the tree do point back up the tree. Do they maybe overwrite the collections above it?

Is it something to do with the initialize() function - does it not interact well with the cache? Is there a way to call setReadOnly (like the Session method) for a collection (it takes an object as a parameter, does that cascade?) or for the entire session?

The collections that are not caching are the exact ones that I initialize in the code above..

Thanks for any advice.


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.