You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ignite.apache.org by "Nikolay Tikhonov (JIRA)" <ji...@apache.org> on 2017/01/17 15:14:26 UTC

[jira] [Comment Edited] (IGNITE-3429) org.hibernate.cache.spi.CacheKey not properly serialized by binary marshaller

    [ https://issues.apache.org/jira/browse/IGNITE-3429?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15826179#comment-15826179 ] 

Nikolay Tikhonov edited comment on IGNITE-3429 at 1/17/17 3:13 PM:
-------------------------------------------------------------------

As workaround for the issue can be used the following {{BinaryIdentityResolver}}

{noformat}
        BinaryConfiguration bCfg = new BinaryConfiguration();

        BinaryTypeConfiguration btCfg = new BinaryTypeConfiguration();

        btCfg.setTypeName(org.hibernate.cache.spi.CacheKey.class.getName());
        btCfg.setIdentityResolver(new BinaryAbstractIdentityResolver() {
            @Override protected int hashCode0(BinaryObject obj) {
                return return obj.field("key").hashCode();
            }

            @Override protected boolean equals0(BinaryObject o1, BinaryObject o2) {
                Object obj0 = o1.field("key");
                Object obj1 = o2.field("key");

                return Objects.equals(obj0, obj1);
            }
        });

        bCfg.setTypeConfigurations(Collections.singleton(btCfg));

        IgniteConfiguration igniteConfiguration = new IgniteConfiguration()
                .setBinaryConfiguration(bCfg);
{noformat}


was (Author: ntikhonov):
As workaround for the issue can be used the following {{BinaryIdentityResolver}}

{noformat}
        BinaryConfiguration bCfg = new BinaryConfiguration();

        BinaryTypeConfiguration btCfg = new BinaryTypeConfiguration();

        btCfg.setTypeName(org.hibernate.cache.spi.CacheKey.class.getName());
        btCfg.setIdentityResolver(new BinaryAbstractIdentityResolver() {
            @Override protected int hashCode0(BinaryObject obj) {
                return ((CacheKey)obj.deserialize()).getKey().hashCode();
            }

            @Override protected boolean equals0(BinaryObject o1, BinaryObject o2) {
                Serializable obj0 = ((CacheKey)o1.deserialize()).getKey();
                Serializable obj1 = ((CacheKey)o2.deserialize()).getKey();

                return obj0.equals(obj1);
            }
        });

        bCfg.setTypeConfigurations(Collections.singleton(btCfg));

        IgniteConfiguration igniteConfiguration = new IgniteConfiguration()
                .setBinaryConfiguration(bCfg);
{noformat}

> org.hibernate.cache.spi.CacheKey not properly serialized by binary marshaller
> -----------------------------------------------------------------------------
>
>                 Key: IGNITE-3429
>                 URL: https://issues.apache.org/jira/browse/IGNITE-3429
>             Project: Ignite
>          Issue Type: Bug
>          Components: cache
>    Affects Versions: 1.6
>            Reporter: Valentin Kulichenko
>            Priority: Critical
>             Fix For: 2.0
>
>
> {{org.hibernate.cache.spi.CacheKey}} is a class used as a key for all entries in the Hibernate L2 cache. This class contains {{type}} field and custom {{equals}} logic where the type is used as a helper and does not participate in comparison. Instances of the same type are producing different hash codes in different JVMs, which actually breaks comparison when binary format is used, where byte arrays are compared.
> The issue is described in more detail here: http://stackoverflow.com/questions/38132263/apache-ignite-as-hibernate-l2-cache-storing-duplicate-entities



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)