[hibernate-issues] [Hibernate-JIRA] Created: (HHH-5980) CacheKey is storing references to entities instead of identifiers

Ian Brandt (JIRA) noreply at atlassian.com
Fri Mar 4 03:53:08 EST 2011


CacheKey is storing references to entities instead of identifiers
-----------------------------------------------------------------

                 Key: HHH-5980
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5980
             Project: Hibernate Core
          Issue Type: Bug
          Components: caching (L2), core
    Affects Versions: 3.6.1
         Environment: Ehcache 2.3.2.
            Reporter: Ian Brandt
         Attachments: hibernate-cachekey-bug.tgz

I'm hitting an issue seemingly similar to HHH-3383, but with {{CacheKey.key}} instead of {{QueryKey.key}}.

Forum Reference: [CacheKey holds reference to entire entity instance as key?|https://forums.hibernate.org/viewtopic.php?f=1&t=1009769&sid=f0f931b62d8d63767444b6c97442f7d2].

In our app this is resulting in what is essentially a significant memory leak, as we have a rather large and highly connected model with cache regions defined for each entity and collection.  We're managing it by clearing the cache via JMX every couple days when our old gen space fills up.  Of course it's not unbounded, where if we were to approximate the retained heap dominated across all the regions where this is occurring we could constrain their max entries so to keep things within available RAM.

I'm attaching a minimal app modeled after the tutorial in the docs that demonstrates at least two cases:

{noformat}
23:56:48,229 ERROR App:63 - CacheKey.key in region 'org.hibernate.bug.cachekey.EntityA.entityBs' 
	isn't an Integer or Integer[], it's an: EntityA [id=1, nk1=2, nk2=3]!
23:56:48,229 ERROR App:63 - CacheKey.key in region 'org.hibernate.bug.cachekey.EntityA.entityBs' 
	isn't an Integer or Integer[], it's an: EntityA [id=2, nk1=4, nk2=5]!
23:56:48,229 ERROR App:63 - CacheKey.key in region 'org.hibernate.bug.cachekey.EntityB' 
	isn't an Integer or Integer[], it's an: EntityB [id1=4, id2=203, nk2=5, nk3=2003]!
23:56:48,229 ERROR App:63 - CacheKey.key in region 'org.hibernate.bug.cachekey.EntityB' 
	isn't an Integer or Integer[], it's an: EntityB [id1=2, id2=103, nk2=3, nk3=1003]!
23:56:48,229 ERROR App:63 - CacheKey.key in region 'org.hibernate.bug.cachekey.EntityB' 
	isn't an Integer or Integer[], it's an: EntityB [id1=2, id2=102, nk2=3, nk3=1002]!
23:56:48,230 ERROR App:63 - CacheKey.key in region 'org.hibernate.bug.cachekey.EntityB' 
	isn't an Integer or Integer[], it's an: EntityB [id1=2, id2=101, nk2=3, nk3=1001]!
23:56:48,230 ERROR App:63 - CacheKey.key in region 'org.hibernate.bug.cachekey.EntityB' 
	isn't an Integer or Integer[], it's an: EntityB [id1=4, id2=200, nk2=5, nk3=2000]!
23:56:48,230 ERROR App:63 - CacheKey.key in region 'org.hibernate.bug.cachekey.EntityB' 
	isn't an Integer or Integer[], it's an: EntityB [id1=2, id2=100, nk2=3, nk3=1000]!
23:56:48,230 ERROR App:63 - CacheKey.key in region 'org.hibernate.bug.cachekey.EntityB' 
	isn't an Integer or Integer[], it's an: EntityB [id1=4, id2=202, nk2=5, nk3=2002]!
23:56:48,230 ERROR App:63 - CacheKey.key in region 'org.hibernate.bug.cachekey.EntityB' 
	isn't an Integer or Integer[], it's an: EntityB [id1=4, id2=201, nk2=5, nk3=2001]!
{noformat}

My apologies that the attached isn't a unit test, but I can't yet claim to understand how this manifests nor the internals enough to narrow it down that far.  I looked briefly at {{FunctionalTestCase}} per http://hibernate.org/issuetracker, but after cloning 3.6 with Git I couldn't find any examples of its usage.  Rather than get hung up I pushed ahead with the attached.

Just FYI in our app we're also seeing {{EntityA}} cached as a key in its own region, as opposed to just its collection regions as above, but I haven't managed to reproduce that yet minimally.  We seem to have many regions with entities in {{CacheKey.key}}, so there may be other situations that I haven't had a chance to single out yet.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list