StandardQueryCache.get() does not handle EntityNotFoundException for natural key lookups

Description

See attached test case and entity.

Current Result:

javax.persistence.EntityNotFoundException: Unable to find com.autodesk.lbs.cs.Dummy with id 1
at org.hibernate.ejb.Ejb3Configuration$Ejb3EntityNotFoundDelegate.handleEntityNotFound(Ejb3Configuration.java:113)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:171)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:223)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:126)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:905)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:873)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:590)
at org.hibernate.type.ManyToOneType.assemble(ManyToOneType.java:219)
at org.hibernate.cache.StandardQueryCache.get(StandardQueryCache.java:155)
at org.hibernate.loader.Loader.getResultFromQueryCache(Loader.java:2184)
at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2147)
at org.hibernate.loader.Loader.list(Loader.java:2117)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1596)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
at org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:328)
at com.autodesk.lbs.cs.DummyTest.naturalKeyCachedQuery(DummyTest.java:69)
at com.autodesk.lbs.cs.DummyTest.naturalKeyCachedQuery(DummyTest.java:61)
at com.autodesk.lbs.cs.DummyTest.testQuery(DummyTest.java:49)

It's expected that a cache invalidation occurs with an entity's natural key when it is removed.

I'll investigate a solution.

Environment

Java 1.5, Maven dependencies:

[INFO] (root)
[INFO] | - org.hibernate:hibernate-validator:jar:3.1.0.GA:compile
[INFO] +- commons-codec:commons-codec:jar:1.3:compile
[INFO] +- javax.persistenceersistence-api:jar:1.0:compile
[INFO] +- org.hibernate:hibernate-core:jar:3.3.0.SP1:compile
[INFO] | +- antlr:antlr:jar:2.7.6:compile
[INFO] | +- commons-collections:commons-collections:jar:3.1:compile
[INFO] | - dom4j:dom4j:jar:1.6.1:compile
[INFO] | - xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] +- org.hibernate:hibernate-annotations:jar:3.4.0.GA:compile
[INFO] | - org.hibernate:ejb3-persistence:jar:1.0.2.GA:compile
[INFO] +- org.hibernate:hibernate-commons-annotations:jar:3.3.0.ga:compile
[INFO] | - org.hibernate:hibernate:jar:3.2.1.ga:compile
[INFO] | +- net.sf.ehcache:ehcache:jar:1.2.3:compile
[INFO] | +- asm:asm-attrs:jar:1.5.3:compile
[INFO] | +- cglib:cglib:jar:2.1_3:compile
[INFO] | - asm:asm:jar:1.5.3:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:3.4.0.GA:compile
[INFO] | - javassist:javassist:jar:3.4.GA:compile
[INFO] +- javax.transaction:jta:jar:1.0.1B:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.5.2:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.5.2:compile
[INFO] +- hsqldb:hsqldb:jar:1.8.0.10:test
[INFO] - junit:junit:jar:4.4:test

Activity

Show:
Steve Ebersole
March 21, 2011, 7:09 PM

Bulk closing stale resolved issues

Gail Badner
August 5, 2010, 6:50 PM

It will be fixed by HHH-5180. I referred to by mistake in my earlier comment. I've corrected that comment.

Steve Ebersole
August 5, 2010, 4:53 PM

Actually nothing here says the fix was done on trunk, nor is 3.6 a target. Gail?

Guenther Demetz
August 5, 2010, 10:54 AM

Hi Gail Badner,

this bugfix, contrary as supposed, seems not have been ported to the trunc through HHH-5220.
I tested today versions 3.6.0 Beta1 and 3.6.0. Beta2 and the bug is still present in this versions.
Only in 3.5.2 it results fixed. Can you please check?

Many thanks in advance
best regards
G.D.

Gail Badner
May 12, 2010, 9:42 PM
Edited

Oops, forgot that deals with the fix for trunk.

Fixed

Assignee

Gail Badner

Reporter

Elias Ross

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major