[hibernate-dev] Caching @EmbeddedId/@Embeddable instances

Galder Zamarreño galder at redhat.com
Fri Jun 8 08:01:52 EDT 2012


On Jun 8, 2012, at 12:35 PM, Galder Zamarreño wrote:

> 
> On Jun 8, 2012, at 12:26 PM, Galder Zamarreño wrote:
> 
>> Hi all,
>> 
>> Re: https://community.jboss.org/message/739399#739399
>> 
>> This guy's using a combo of @EmbeddedId and @Embeddable in the tests his provided, and this is resulting in cache key serialized payloads differing for identical instances. Even in between runs, the last bit of the payload varies. This obviously results in keys not being found in the cache. 

The problem seems to come from here:

CacheKey -> org.hibernate.type.TypeFactory$TypeScopeImpl -> SessionFactoryImpl -> uuid

So, each CacheKey is this case contains the UUID of the session factory, and since each node's session factories are different, the UUIDs will be too, which results in different payloads for the same key.

This would appear to be a bug in the Hibernate side? 2LC providers do nothing about CacheKey, they just know that an object needs to be serialized.

Btw, that a simple key like the one in the example provided generates 3KB of byte[] sounds pretty excessive...

>> 
>> Apart from this issue which I'm currently investigating, I've spotted that when the CacheKey is marshalled, it also marshalls the entity as part of the key. That sounds rather inefficient, so is this guy:
> 
> ^ I think this statement is wrong, bear with me while I confirm.

^ I was wrong with this.

> 
>> 
>> a) using the right pattenr for @EmbeddedId + @Embeddable
>> b) is Hibernate behaving the right way here by having a reference to the entity from cache key
>> 
>> Cheers,
>> --
>> Galder Zamarreño
>> Sr. Software Engineer
>> Infinispan, JBoss Cache
>> _______________________________________________
>> hibernate-dev mailing list
>> hibernate-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/hibernate-dev
> 
> --
> Galder Zamarreño
> Sr. Software Engineer
> Infinispan, JBoss Cache
> 
> 
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev

--
Galder Zamarreño
Sr. Software Engineer
Infinispan, JBoss Cache




More information about the hibernate-dev mailing list