-->
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.  [ 5 posts ] 
Author Message
 Post subject: Problem with Hibernate and JBoss Cache's optimistic locking
PostPosted: Sat Mar 10, 2007 4:49 pm 
Newbie

Joined: Thu Mar 31, 2005 5:01 pm
Posts: 16
Hibernate version: 3.2.2.ga

JBoss Cache version: 1.4.1.sp2

Hibernate config XML:
Code:
<hibernate-configuration>
   <session-factory>
        <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="connection.url">jdbc:hsqldb:mem:temp</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.HSQLDialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <!--property name="current_session_context_class">thread</property-->

        <property name="hibernate.cache.use_second_level_cache">true</property>
        <property name="cache.provider_class">org.hibernate.cache.OptimisticTreeCacheProvider</property>
       <property name="transaction.manager_lookup_class">com.medq.test.DummyTransactionManagerLookup</property>       

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">create</property>

        <mapping class="com.medq.test.A"/>   
        <mapping class="com.medq.test.B"/>   
     </session-factory>
</hibernate-configuration>


Annotated entities:
Code:
@Entity
@Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL)
public class A {
   
   @Id
   Integer id;
   
   String s;
   
   @OneToMany(fetch=FetchType.EAGER, mappedBy="a", cascade=CascadeType.ALL)
   @Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL)
   List<B> bs = new LinkedList<B>();

}


Code:
@Entity
@Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL)
public class B {
   @Id
   int id;
   
   @ManyToOne
   A a;
}


Code between sessionFactory.openSession() and session.close():
Code:
            // Use dummy transaction stuff provided by JBoss Cache for this test code
            UserTransaction tx= new DummyUserTransaction(DummyTransactionManager.getInstance());
            
            tx.begin();
            A a = new A();
            a.id = 1;
            session.persist(a);
            session.flush();
            session.clear();
            tx.commit();
            
            tx.begin();
            session.get(A.class, 1);
            session.createSQLQuery("update A set s = 'blah'").executeUpdate(); // kaboom!!!
            tx.commit();


Full stack trace of any exception that occurs:
Code:
org.hibernate.cache.CacheException: org.jboss.cache.CacheException: Unable to find parent node with Fqn /com/medq/test/A
   at org.hibernate.cache.OptimisticTreeCache.clear(OptimisticTreeCache.java:169)
   at org.hibernate.cache.TransactionalCache.clear(TransactionalCache.java:124)
   at org.hibernate.impl.SessionFactoryImpl.evictCollection(SessionFactoryImpl.java:874)
   at org.hibernate.action.BulkOperationCleanupAction.evictCollectionRegions(BulkOperationCleanupAction.java:142)
   at org.hibernate.action.BulkOperationCleanupAction.init(BulkOperationCleanupAction.java:103)
   at org.hibernate.engine.query.NativeSQLQueryPlan.coordinateSharedCacheCleanup(NativeSQLQueryPlan.java:134)
   at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:144)
   at org.hibernate.impl.SessionImpl.executeNativeUpdate(SessionImpl.java:1163)
   at org.hibernate.impl.SQLQueryImpl.executeUpdate(SQLQueryImpl.java:334)
   at com.medq.test.TestHibernate.main(TestHibernate.java:39)
Caused by: org.jboss.cache.CacheException: Unable to find parent node with Fqn /com/medq/test/A
   at org.jboss.cache.interceptors.OptimisticNodeInterceptor.removeNode(OptimisticNodeInterceptor.java:218)
   at org.jboss.cache.interceptors.OptimisticNodeInterceptor.invoke(OptimisticNodeInterceptor.java:110)
   at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
   at org.jboss.cache.interceptors.EvictionInterceptor.invoke(EvictionInterceptor.java:88)
   at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
   at org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor.invoke(OptimisticCreateIfNotExistsInterceptor.java:69)
   at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
   at org.jboss.cache.interceptors.OptimisticValidatorInterceptor.invoke(OptimisticValidatorInterceptor.java:84)
   at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
   at org.jboss.cache.interceptors.OptimisticLockingInterceptor.invoke(OptimisticLockingInterceptor.java:126)
   at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
   at org.jboss.cache.interceptors.TxInterceptor.handleNonTxMethod(TxInterceptor.java:365)
   at org.jboss.cache.interceptors.TxInterceptor.invoke(TxInterceptor.java:160)
   at org.jboss.cache.interceptors.Interceptor.invoke(Interceptor.java:68)
   at org.jboss.cache.interceptors.CacheMgmtInterceptor.invoke(CacheMgmtInterceptor.java:183)
   at org.jboss.cache.TreeCache.invokeMethod(TreeCache.java:5776)
   at org.jboss.cache.TreeCache.remove(TreeCache.java:3855)
   at org.jboss.cache.TreeCache.remove(TreeCache.java:3438)
   at org.hibernate.cache.OptimisticTreeCache.clear(OptimisticTreeCache.java:166)
   ... 9 more


Name and version of the database you are using: HSQLDB 1.8.0

The generated SQL:
Code:
Hibernate: insert into A (s, id) values (?, ?)
Hibernate: select bs0_.a_id as a2_1_, bs0_.id as id1_, bs0_.id as id1_0_, bs0_.a_id as a2_1_0_ from B bs0_ where bs0_.a_id=?


We saw this problem in our JBoss/EJB3 application. I reproduced it in a test J2SE application, the code from which is posted above.

The problem occurs when Hibernate attempts to evict the A.bs collection. Because the A entity has already been evicted by BulkOperationCleanupAction, JBoss Cache can't find a WorkspaceNode for the parent of A.bs.

This is what JBoss Cache sees Hibernate doing (in pseudo-code):
Code:
put com/medq/test/A/bs/com.medq.test.A.bs#1 key value
remove /com/medq/test/B
remove /com/medq/test/A
remove /com/medq/test/A/bs // kaboom!!!


Obviously removing "/com/medq/test/A" also removes "/com/medq/test/A/bs", so the last line is superfluous (as well as causing an exception to be thrown).

Is there a reason why org.hibernate.cache.OptimisticTreeCache.clear doesn't call option.setFailSilently(true)? The exception above would be swallowed by JBoss Cache if it did.


Last edited by rworsnop on Sun Mar 11, 2007 2:10 pm, edited 3 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 10, 2007 5:37 pm 
Newbie

Joined: Thu Mar 31, 2005 5:01 pm
Posts: 16
By the way, I've found a workaround:

Code:
   @OneToMany(fetch=FetchType.EAGER, mappedBy="a", cascade=CascadeType.ALL)
   @Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL, region="collections/com/medq/test/A/bs")
   List<B> bs = new LinkedList<B>();


When I set the region so that collections are stored in a different part of the tree, they don't get whacked along with the parent entity.


Last edited by rworsnop on Sun Mar 11, 2007 10:41 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 11, 2007 6:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Not my area of knowledge but sounds like a reasonable JIRA entry.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 11, 2007 12:08 pm 
Newbie

Joined: Thu Mar 31, 2005 5:01 pm
Posts: 16
Here's the bug report:

http://opensource.atlassian.com/project ... e/HHH-2486


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 11, 2007 2:32 pm 
Newbie

Joined: Thu Mar 31, 2005 5:01 pm
Posts: 16
I have also raised this issue on the JBoss Cache forum:

http://www.jboss.com/index.html?module= ... &p=4026973


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.