-->
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: Accessing Second-Level Cache
PostPosted: Sun Jun 20, 2004 1:57 pm 
Beginner
Beginner

Joined: Fri Jan 23, 2004 4:29 pm
Posts: 39
How can I access the second-level cache provider? I want to retrieve an object from the second-level cache.

Is there something like sessionFactory.getCacheProvider().getCache().get("region", key)?


Top
 Profile  
 
 Post subject: accessing second-level cache
PostPosted: Tue Jun 22, 2004 8:15 am 
Beginner
Beginner

Joined: Fri Jan 23, 2004 4:29 pm
Posts: 39
I had a look at the source code and think I can get the object from the second-level cache like this:

Code:
sessionFactory.getPersister(Node.class).getCache().get(key,System.currentTimeMillis());


I have not yet tested it but will do that today.

Can someone verify that the second parameter is supposed to be System.currentTimeMillis().


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 12:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Don't mess with the cache. It doesn't work like you expect. Read the code and you'll see.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 2:10 pm 
Beginner
Beginner

Joined: Fri Jan 23, 2004 4:29 pm
Posts: 39
Ok. I'll try not to mess with the cache then.

I still have the following problem though.

I have a Node class that has a set of subNodes.

After I delete a subNode (with JDBC not Hibernate) I try to get the subNodes. But then Hibernate throws a

Code:
net.sf.hibernate.ObjectNotFoundException: No row with the given identifier exists: 35982


This is I guess because the cache for subNodes still contain the deleted subNode.

I evicted the node itself from the cache with
Code:
sessionFactory.evict(Node.class, key);


So I'm assuming that I need to evict it from the subNodes cache also.
How do I do it?
Code:
public void evictCollection(String roleName,
                            Serializable id)
                     throws HibernateException


What is the roleName? Is it the classname + the name of the collection?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 2:13 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
if this class is used in both ORM and JDBC, the most secure option is not to cache it...

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 2:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Not necessarily, if there is only one or two places it is used by JDBC....


....and yes, it is of form package.Class.propertyName


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 4:05 pm 
Beginner
Beginner

Joined: Fri Jan 23, 2004 4:29 pm
Posts: 39
I found one error in my post. I am using Hibernate to delete the subNode.
I'm also using JDBC in some parts of my code but not to delete the nodes.

So the second-level cache should not contain the deleted item. But this seems to be the case. Here's the log:

Code:
net.sf.hibernate.cache.ReadWriteCache: Caching: 294 // LOADING NODE
net.sf.hibernate.cache.ReadWriteCache: Cached: 294
net.sf.hibernate.cache.ReadWriteCache: Caching: 192
net.sf.hibernate.cache.ReadWriteCache: Cached: 192
net.sf.hibernate.cache.ReadWriteCache: Cache lookup: 13936 // Parent node
net.sf.hibernate.cache.ReadWriteCache: Cache miss: 13936
net.sf.hibernate.cache.ReadWriteCache: Caching: 13936
net.sf.hibernate.cache.ReadWriteCache: Cached: 13936
net.sf.hibernate.cache.ReadWriteCache: Cache lookup: 13936
net.sf.hibernate.cache.ReadWriteCache: Cache miss: 13936
net.sf.hibernate.cache.ReadWriteCache: Caching: 14040
net.sf.hibernate.cache.ReadWriteCache: Cached: 14040
net.sf.hibernate.cache.ReadWriteCache: Caching: 13936
net.sf.hibernate.cache.ReadWriteCache: Cached: 13936
net.sf.hibernate.cache.ReadWriteCache: Cache lookup: 14040
net.sf.hibernate.cache.ReadWriteCache: Cache miss: 14040
net.sf.hibernate.cache.ReadWriteCache: Caching: 14040
net.sf.hibernate.cache.ReadWriteCache: Cached: 14040
net.sf.hibernate.cache.ReadWriteCache: Caching: 14040
net.sf.hibernate.cache.ReadWriteCache: Item was already cached: 14040 // DELETING NODE
net.sf.hibernate.cache.ReadWriteCache: Invalidating: 14040
net.sf.hibernate.cache.ReadWriteCache: Invalidating: 14040
net.sf.hibernate.cache.ReadWriteCache: Releasing: 14040
net.sf.hibernate.cache.ReadWriteCache: Releasing: 14040
net.sf.hibernate.cache.ReadWriteCache: Cache lookup: 13936 // Loading parent node and subNodes
net.sf.hibernate.cache.ReadWriteCache: Cache hit: 13936
net.sf.hibernate.cache.ReadWriteCache: Cache lookup: 13936
net.sf.hibernate.cache.ReadWriteCache: Cache hit: 13936
net.sf.hibernate.cache.ReadWriteCache: Cache lookup: 14040 // Item is still in the subNodes collection. So lazy loader throws ObjectNotFoundException because the node with ID 14040 was just deleted.
net.sf.hibernate.cache.ReadWriteCache: Cached item was locked: 14040


The set of subNodes is configured like this:

Code:
   <set name="subNodes" inverse="true" lazy="true" order-by="name asc">
      <cache usage="read-write"/>
      <key column="parent_node_id"/>
      <one-to-many class="project.Node"/>
   </set>


The class configuration is the following:

Code:
<class
    name="project.Node"
    table="nodes"
    dynamic-update="true"
    dynamic-insert="true"
    proxy="project.Node"
>
   <cache usage="read-write"/>


Oscache is using:

Code:
project.Node.capacity=100
project.Node.subNodes.capacity=100


The node is deleted with:
Code:
session.delete("from nodes in .... where node.id in (xxx)")


I guess session.delete does not update the second-level cache as is the case with JDBC.

So I can only see two ways to solve my problem:

1. Load the objects with session.load and then call session.delete(node). Not as performant as one SQL query. But should work.
2. Somehow update the cache manually but this is not advisable.

Am I correct in my assumptions?


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.