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

Fred edited comment on IGNITE-3429 at 10/5/16 5:36 PM:
-------------------------------------------------------

I put in a temporary workaround in the time being which sets SessionFactory to 
null:

public class SgrOptimizedMarshaller extends OptimizedMarshaller {

        @Override
        public byte[] marshal(Object obj) throws IgniteCheckedException {

                if (obj instanceof CacheKey) {
                        CacheKey key = (CacheKey) obj;
                        Class<?> cacheKeyClazz = obj.getClass();

                        try {
                                Field typeField = 
cacheKeyClazz.getDeclaredField("type");
                                typeField.setAccessible(true);
                                Type hibernateType = (Type) typeField.get(key);
                                if (hibernateType instanceof ComponentType) {
                                        ComponentType componentType = 
(ComponentType) hibernateType;
                                        Class<?> componentTypeClazz = 
componentType.getClass();
                                        Field componentTypeField = 
componentTypeClazz.getDeclaredField("typeScope");
                                        componentTypeField.setAccessible(true);
                                        componentTypeField.set(componentType, 
null);
                                }
                        } catch (Exception ex) {
                                System.out.println(ex.toString());
                        }
                }
                return super.marshal(obj);
        }

}


was (Author: fwvista):
I put in a temporary workaround in the time being which sets SessionFactory to 
null:

```
public class SgrOptimizedMarshaller extends OptimizedMarshaller {

        @Override
        public byte[] marshal(Object obj) throws IgniteCheckedException {

                if (obj instanceof CacheKey) {
                        CacheKey key = (CacheKey) obj;
                        Class<?> cacheKeyClazz = obj.getClass();

                        try {
                                Field typeField = 
cacheKeyClazz.getDeclaredField("type");
                                typeField.setAccessible(true);
                                Type hibernateType = (Type) typeField.get(key);
                                if (hibernateType instanceof ComponentType) {
                                        ComponentType componentType = 
(ComponentType) hibernateType;
                                        Class<?> componentTypeClazz = 
componentType.getClass();
                                        Field componentTypeField = 
componentTypeClazz.getDeclaredField("typeScope");
                                        componentTypeField.setAccessible(true);
                                        componentTypeField.set(componentType, 
null);
                                }
                        } catch (Exception ex) {
                                System.out.println(ex.toString());
                        }
                }
                return super.marshal(obj);
        }

}
```

> 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: 1.8
>
>
> {{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)

Reply via email to