-->
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: concurrent reads + one write cause ObjectNotFoundException
PostPosted: Mon Jan 27, 2014 4:56 am 
Beginner
Beginner

Joined: Fri May 12, 2006 9:58 am
Posts: 32
I use hibernate 3.6.8, ehcache 2.4.5 (also tried with latest 2.8.0), jvm 1.6.0_22 in a high traffic site and sometimes I experience ObjectNotFoundException: No row with the given identifier exists: [com.example.Foo#123] when a new Foo (in this case with id 123) is created via the simplest code possible:
Code:
Foo foo = new Foo();
session.save(foo);

The reason is that in all pages of this high traffic site I get all Foos like that:
Code:
session.createQuery("from Foo").setCacheable(true).list();

Table storing Foos contains 1000 rows and the entity is cached in ehcache:
Code:
<class-cache class="com.example.Foo" usage="read-write" />

Other possibly relevant parts of my hibernate configuration are:
Code:
<property name="connection.url">jdbc:mysql://localhost:3306/example?characterEncoding=UTF-8</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>

<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>       
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">60</property>
<property name="hibernate.c3p0.min_size">10</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.max_statements">0</property>
<property name="hibernate.c3p0.timeout">0</property>
<property name="hibernate.c3p0.acquireRetryAttempts">1</property>
<property name="hibernate.c3p0.acquireRetryDelay">1</property>

<property name="hibernate.show_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>

<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.jdbc.use_scrollable_resultset">true</property>

<property name="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</property>
<property name="net.sf.ehcache.configurationResourceName">/ehcache.xml</property>
<property name="hibernate.cache.use_query_cache">true</property>


I suspect that what happens is that ehcache query cache is updated with the new entity id (123) id but the entity cache is not yet updated with the contents of that entity. I reproduce this fairly easily locally using JMeter.

Any idea on how to solve this?

stacktrace:
Code:
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.example.Foo#123]
   at org.hibernate.impl.SessionFactoryImpl$2.handleEntityNotFound(SessionFactoryImpl.java:435)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:233)
   at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
   at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
   at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1038)
   at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:630)
   at org.hibernate.type.ManyToOneType.assemble(ManyToOneType.java:236)
   at org.hibernate.cache.StandardQueryCache.get(StandardQueryCache.java:153)
   at org.hibernate.loader.Loader.getResultFromQueryCache(Loader.java:2366)
   at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2309)
   at org.hibernate.loader.Loader.list(Loader.java:2268)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:459)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:365)

ehcache config:
Code:
<ehcache updateCheck="false">

    <diskStore path="java.io.tmpdir" />
    <defaultCache maxElementsInMemory="0" eternal="false" overflowToDisk="false" />
    <cache name="org.hibernate.cache.StandardQueryCache" maxElementsInMemory="10000" eternal="false" overflowToDisk="false" />
    <cache name="org.hibernate.cache.UpdateTimestampsCache" maxElementsInMemory="10000" eternal="true" overflowToDisk="false" />

    <cache name="com.example.Foo" maxElementsInMemory="10000" eternal="true" overflowToDisk="false" />

</ehcache>


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.