-->
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.  [ 1 post ] 
Author Message
 Post subject: Problems invalidating OSCache, cascading associations
PostPosted: Thu Jul 01, 2004 9:55 am 
Beginner
Beginner

Joined: Mon Feb 09, 2004 6:49 am
Posts: 21
Hi

I've been stuck on this issue regarding OSCache and a simple object tree.
I'm using Hibernate 2.1.2, OSCache 2.0.2, MS SQL server 2000 and jTDS 0.8

I have a object tree somewhat like this:

A Holds a set of Bs
/ | \
B1 B2 B3 wich each holds a set of Cs
/ \ / \ / \
C CC CC C

Now, the problem occurs when deleting a B-object after deleting a C-object. What happens then is that the cache invalidates the C-object, but not the association to it in the B-object. So the result is a LazyInitializationException.

So my question is; how may I specify that OSCache shall invalidate not only the C-object but also the B-object. Because the B-object gets updated in the DB, if I turn off the cache things work perfectly fine.

The set of C's are mapped like this:

Code:
<set
            name="Cs"
            lazy="true"
            inverse="true"
            cascade="all"
            sort="unsorted"
        >
            <cache
                usage="read-write"
             />

              <key
                  column="B"
              >
              </key>

              <one-to-many
                  class="com.testing.C"
              />
        </set>


And the association from C to B like this:
Code:
<many-to-one
            name="C"
            class="com.testing.C"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            access="property"
            column="B"
        />


The action goes something like this:

Code:
service.delete(C);

//This doesn't make any difference
B = service.get(B.class,b.getId());
service.update(B);

service.delete(B)


I'm using spring and each service methods has its own transaction and session. Here goes the exception:

net.sf.hibernate.LazyInitializationException: Exception initializing proxy: [com.corporater.Kpi#1088409558896]
...
.
.
Caused by: net.sf.hibernate.ObjectNotFoundException: No row with the given identifier exists: 1088409558896, of class: com.corporater.Kpi
at net.sf.hibernate.ObjectNotFoundException.throwIfNull


And some relevant log output:

15:35:13,981 INFO HibernateTransactionManager:315 - Initiating transaction commit
15:35:13,981 DEBUG HibernateTransactionManager:382 - Committing Hibernate transaction on session [net.sf.hibernate.impl.SessionImpl@457d21]
15:35:13,981 DEBUG ReadWriteCache:106 - Invalidating: 1088688913434
15:35:13,981 DEBUG SQL:237 - delete from Kpi where globalId=? and timestamp=?
15:35:13,996 DEBUG ReadWriteCache:178 - Releasing: 1088688913434
15:35:13,996 DEBUG HibernateTransactionManager:477 - Triggering afterCompletion synchronization
15:35:13,996 DEBUG TransactionSynchronizationManager:232 - Clearing transaction synchronization
15:35:13,996 DEBUG TransactionSynchronizationManager:163 - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@1c18a4c] for key [org.apache.commons.dbcp.BasicDataSource@1568fb5] from thread [main]
15:35:13,996 DEBUG TransactionSynchronizationManager:163 - Removed value [org.springframework.orm.hibernate.SessionHolder@1a0ae6] for key [net.sf.hibernate.impl.SessionFactoryImpl@5c3987] from thread [main]
15:35:13,996 DEBUG HibernateTransactionManager:475 - Closing Hibernate session [net.sf.hibernate.impl.SessionImpl@457d21] after transaction
15:35:13,996 DEBUG SessionFactoryUtils:348 - Closing Hibernate session
15:35:13,996 DEBUG TransactionInterceptor:168 - Getting transaction for method 'updateFocusarea' in class [com.corporater.I_BSCService]
15:35:13,996 DEBUG HibernateTransactionManager:163 - Using transaction object [org.springframework.orm.hibernate.HibernateTransactionObject@1dfd868]
15:35:13,996 DEBUG HibernateTransactionManager:214 - Creating new transaction
15:35:13,996 DEBUG SessionFactoryUtils:183 - Opening Hibernate session
15:35:13,996 DEBUG HibernateTransactionManager:271 - Opened new session [net.sf.hibernate.impl.SessionImpl@f894ce] for Hibernate transaction
15:35:13,996 DEBUG HibernateTransactionManager:280 - Beginning Hibernate transaction on session [net.sf.hibernate.impl.SessionImpl@f894ce]
15:35:14,012 DEBUG TransactionSynchronizationManager:141 - Bound value [org.springframework.orm.hibernate.SessionHolder@1f1680f] for key [net.sf.hibernate.impl.SessionFactoryImpl@5c3987] to thread [main]
15:35:14,012 DEBUG TransactionSynchronizationManager:141 - Bound value [org.springframework.jdbc.datasource.ConnectionHolder@1e6e305] for key [org.apache.commons.dbcp.BasicDataSource@1568fb5] to thread [main]
15:35:14,012 DEBUG TransactionSynchronizationManager:192 - Initializing transaction synchronization
15:35:14,012 DEBUG TransactionSynchronizationManager:117 - Retrieved value [org.springframework.orm.hibernate.SessionHolder@1f1680f] for key [net.sf.hibernate.impl.SessionFactoryImpl@5c3987] bound to thread [main]
15:35:14,012 DEBUG TransactionInterceptor:208 - Invoking commit for transaction on method 'updateFocusarea' in class [com.corporater.I_BSCService]
15:35:14,012 DEBUG HibernateTransactionManager:432 - Triggering beforeCommit synchronization
15:35:14,012 DEBUG HibernateTransactionManager:447 - Triggering beforeCompletion synchronization
15:35:14,012 INFO HibernateTransactionManager:315 - Initiating transaction commit
15:35:14,012 DEBUG HibernateTransactionManager:382 - Committing Hibernate transaction on session [net.sf.hibernate.impl.SessionImpl@f894ce]
15:35:14,012 DEBUG ReadWriteCache:106 - Invalidating: 1088688913403
15:35:14,012 DEBUG SQL:237 - update Focusarea set timestamp=?, description=?, weight=?, x=?, y=?, sortIndex=?, perspective=?, name=? where globalId=? and timestamp=?
15:35:14,012 DEBUG ReadWriteCache:227 - Updating: 1088688913403
15:35:14,012 DEBUG ReadWriteCache:243 - Updated: 1088688913403
15:35:14,012 DEBUG HibernateTransactionManager:477 - Triggering afterCompletion synchronization
15:35:14,012 DEBUG TransactionSynchronizationManager:232 - Clearing transaction synchronization
15:35:14,012 DEBUG TransactionSynchronizationManager:163 - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@1e6e305] for key [org.apache.commons.dbcp.BasicDataSource@1568fb5] from thread [main]
15:35:14,012 DEBUG TransactionSynchronizationManager:163 - Removed value [org.springframework.orm.hibernate.SessionHolder@1f1680f] for key [net.sf.hibernate.impl.SessionFactoryImpl@5c3987] from thread [main]
15:35:14,012 DEBUG HibernateTransactionManager:475 - Closing Hibernate session [net.sf.hibernate.impl.SessionImpl@f894ce] after transaction
15:35:14,012 DEBUG SessionFactoryUtils:348 - Closing Hibernate session
15:35:14,012 DEBUG TransactionInterceptor:168 - Getting transaction for method 'deleteFocusarea' in class [com.corporater.I_BSCService]
15:35:14,028 DEBUG HibernateTransactionManager:163 - Using transaction object [org.springframework.orm.hibernate.HibernateTransactionObject@106daba]
15:35:14,028 DEBUG HibernateTransactionManager:214 - Creating new transaction
15:35:14,028 DEBUG SessionFactoryUtils:183 - Opening Hibernate session
15:35:14,028 DEBUG HibernateTransactionManager:271 - Opened new session [net.sf.hibernate.impl.SessionImpl@1021f34] for Hibernate transaction
15:35:14,028 DEBUG HibernateTransactionManager:280 - Beginning Hibernate transaction on session [net.sf.hibernate.impl.SessionImpl@1021f34]
15:35:14,028 DEBUG TransactionSynchronizationManager:141 - Bound value [org.springframework.orm.hibernate.SessionHolder@4eb043] for key [net.sf.hibernate.impl.SessionFactoryImpl@5c3987] to thread [main]
15:35:14,028 DEBUG TransactionSynchronizationManager:141 - Bound value [org.springframework.jdbc.datasource.ConnectionHolder@163956] for key [org.apache.commons.dbcp.BasicDataSource@1568fb5] to thread [main]
15:35:14,028 DEBUG TransactionSynchronizationManager:192 - Initializing transaction synchronization
15:35:14,028 DEBUG TransactionSynchronizationManager:117 - Retrieved value [org.springframework.orm.hibernate.SessionHolder@4eb043] for key [net.sf.hibernate.impl.SessionFactoryImpl@5c3987] bound to thread [main]
15:35:14,028 DEBUG ReadWriteCache:68 - Cache lookup: 1088688913371
15:35:14,028 DEBUG ReadWriteCache:78 - Cache hit: 1088688913371
15:35:14,028 DEBUG ReadWriteCache:68 - Cache lookup: 1088688913371
15:35:14,028 DEBUG ReadWriteCache:87 - Cached item was locked: 1088688913371
15:35:14,028 DEBUG SQL:237 - select focusareas0_.globalId as globalId__, focusareas0_.perspective as perspect8___, focusareas0_.globalId as globalId0_, focusareas0_.timestamp as timestamp0_, focusareas0_.description as descript3_0_, focusareas0_.weight as weight0_, focusareas0_.x as x0_, focusareas0_.y as y0_, focusareas0_.sortIndex as sortIndex0_, focusareas0_.perspective as perspect8_0_, focusareas0_.name as name0_ from Focusarea focusareas0_ where focusareas0_.perspective=?
15:35:14,043 DEBUG ReadWriteCache:132 - Caching: 1088688913418
15:35:14,043 DEBUG ReadWriteCache:152 - Item was already cached: 1088688913418
15:35:14,043 DEBUG ReadWriteCache:132 - Caching: 1088688913371
15:35:14,043 DEBUG ReadWriteCache:143 - Cached: 1088688913371
15:35:14,043 DEBUG TransactionSynchronizationManager:117 - Retrieved value [org.springframework.orm.hibernate.SessionHolder@4eb043] for key [net.sf.hibernate.impl.SessionFactoryImpl@5c3987] bound to thread [main]
15:35:14,043 DEBUG ReadWriteCache:68 - Cache lookup: 1088688913465
15:35:14,043 DEBUG ReadWriteCache:78 - Cache hit: 1088688913465
15:35:14,043 DEBUG SQL:237 - select kpilimits0_.globalId as globalId__, kpilimits0_.kpi as kpi__, kpilimits0_.globalId as globalId0_, kpilimits0_.timestamp as timestamp0_, kpilimits0_.hi as hi0_, kpilimits0_.lo as lo0_, kpilimits0_.max as max0_, kpilimits0_.min as min0_, kpilimits0_.dateValid as dateValid0_, kpilimits0_.kpi as kpi0_ from KpiLimit kpilimits0_ where kpilimits0_.kpi=?
15:35:14,043 DEBUG ReadWriteCache:68 - Cache lookup: 1088688913450
15:35:14,059 DEBUG ReadWriteCache:78 - Cache hit: 1088688913450
15:35:14,059 DEBUG SQL:237 - select kpilimits0_.globalId as globalId__, kpilimits0_.kpi as kpi__, kpilimits0_.globalId as globalId0_, kpilimits0_.timestamp as timestamp0_, kpilimits0_.hi as hi0_, kpilimits0_.lo as lo0_, kpilimits0_.max as max0_, kpilimits0_.min as min0_, kpilimits0_.dateValid as dateValid0_, kpilimits0_.kpi as kpi0_ from KpiLimit kpilimits0_ where kpilimits0_.kpi=?
15:35:14,059 DEBUG ReadWriteCache:68 - Cache lookup: 1088688913434
15:35:14,059 DEBUG ReadWriteCache:87 - Cached item was locked: 1088688913434
15:35:14,059 DEBUG SQL:237 - select kpi0_.globalId as globalId0_, kpi0_.timestamp as timestamp0_, kpi0_.sortIndex as sortIndex0_, kpi0_.active as active0_, kpi0_.algorithmType as algorith5_0_, kpi0_.datasource as datasource0_, kpi0_.description as descript7_0_, kpi0_.email as email0_, kpi0_.focusarea as focusarea0_, kpi0_.frequency as frequency0_, kpi0_.intention as intention0_, kpi0_.limitCalcIndex as limitCa12_0_, kpi0_.limitComment as limitCo13_0_, kpi0_.period as period0_, kpi0_.responsible as respons15_0_, kpi0_.showLimitComment as showLim16_0_, kpi0_.showLimitDesc as showLim17_0_, kpi0_.trendComment as trendCo18_0_, kpi0_.trendFunction as trendFu19_0_, kpi0_.type as type0_, kpi0_.weight as weight0_, kpi0_.linked as linked0_, kpi0_.name as name0_ from Kpi kpi0_ where kpi0_.globalId=?
15:35:14,075 ERROR LazyInitializer:63 - Exception initializing proxy
net.sf.hibernate.ObjectNotFoundException: No row with the given identifier exists: 1088688913434, of class: com.corporater.Kpi


Try to ignore that the names in the logoutput is not B and C, but kpi is the C object, and focusarea is the B object

Ok this one is getting long but i think you'll have to se the OSCache.properties and hibernatecache settings as well:

Code:
# CACHE IN MEMORY
# If you want to disable memory caching, just uncomment this line.
#cache.memory=false

# CACHE LISTENERS
cache.event.listeners=com.opensymphony.oscache.extra.CacheMapAccessEventListenerImpl

# CACHE ALGORITHM
cache.algorithm=com.opensymphony.oscache.base.algorithm.LRUCache

# CACHE SIZE
cache.capacity=1000

# CACHE UNLIMITED DISK
cache.unlimited.disk=false


from applicationContext.xml:
Code:
<prop key="hibernate.cache.use_query_cache">true</prop>
            
            <prop key="hibernate.cache.provider_class">net.sf.hibernate.cache.OSCacheProvider</prop>


I hope someone can tell me where I'm stupid, thanxs in advance

regards dag


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.