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?