You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2017/04/26 11:23:37 UTC

[01/16] ignite git commit: ignite-1794 Refactored hibernate modules, switched to hibernate 5.1

Repository: ignite
Updated Branches:
  refs/heads/ignite-2.0 c9cd761e0 -> ee1b19d3f


http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListenerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListenerSelfTest.java b/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListenerSelfTest.java
deleted file mode 100644
index c4d6120..0000000
--- a/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListenerSelfTest.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.store.hibernate;
-
-import java.io.Serializable;
-import java.util.Map;
-import javax.cache.Cache;
-import javax.cache.configuration.Factory;
-import javax.cache.integration.CacheLoaderException;
-import javax.cache.integration.CacheWriterException;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.Table;
-import org.apache.ignite.cache.store.CacheStore;
-import org.apache.ignite.cache.store.CacheStoreAdapter;
-import org.apache.ignite.cache.store.CacheStoreSession;
-import org.apache.ignite.cache.store.CacheStoreSessionListener;
-import org.apache.ignite.cache.store.CacheStoreSessionListenerAbstractSelfTest;
-import org.apache.ignite.cache.store.jdbc.CacheJdbcStoreSessionListener;
-import org.apache.ignite.lang.IgniteBiInClosure;
-import org.apache.ignite.resources.CacheStoreSessionResource;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.Transaction;
-import org.hibernate.cfg.Configuration;
-
-/**
- * Tests for {@link CacheJdbcStoreSessionListener}.
- */
-public class CacheHibernateStoreSessionListenerSelfTest extends CacheStoreSessionListenerAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override protected Factory<? extends CacheStore<Integer, Integer>> storeFactory() {
-        return new Factory<CacheStore<Integer, Integer>>() {
-            @Override public CacheStore<Integer, Integer> create() {
-                return new Store();
-            }
-        };
-    }
-
-    /** {@inheritDoc} */
-    @Override protected Factory<CacheStoreSessionListener> sessionListenerFactory() {
-        return new Factory<CacheStoreSessionListener>() {
-            @Override public CacheStoreSessionListener create() {
-                CacheHibernateStoreSessionListener lsnr = new CacheHibernateStoreSessionListener();
-
-                SessionFactory sesFactory = new Configuration().
-                    setProperty("hibernate.connection.url", URL).
-                    addAnnotatedClass(Table1.class).
-                    addAnnotatedClass(Table2.class).
-                    buildSessionFactory();
-
-                lsnr.setSessionFactory(sesFactory);
-
-                return lsnr;
-            }
-        };
-    }
-
-    /**
-     */
-    private static class Store extends CacheStoreAdapter<Integer, Integer> {
-        /** */
-        private static String SES_CONN_KEY = "ses_conn";
-
-        /** */
-        @CacheStoreSessionResource
-        private CacheStoreSession ses;
-
-        /** {@inheritDoc} */
-        @Override public void loadCache(IgniteBiInClosure<Integer, Integer> clo, Object... args) {
-            loadCacheCnt.incrementAndGet();
-
-            checkSession();
-        }
-
-        /** {@inheritDoc} */
-        @Override public Integer load(Integer key) throws CacheLoaderException {
-            loadCnt.incrementAndGet();
-
-            checkSession();
-
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void write(Cache.Entry<? extends Integer, ? extends Integer> entry)
-            throws CacheWriterException {
-            writeCnt.incrementAndGet();
-
-            checkSession();
-
-            if (write.get()) {
-                Session hibSes = ses.attachment();
-
-                switch (ses.cacheName()) {
-                    case "cache1":
-                        hibSes.save(new Table1(entry.getKey(), entry.getValue()));
-
-                        break;
-
-                    case "cache2":
-                        if (fail.get())
-                            throw new CacheWriterException("Expected failure.");
-
-                        hibSes.save(new Table2(entry.getKey(), entry.getValue()));
-
-                        break;
-
-                    default:
-                        throw new CacheWriterException("Wring cache: " + ses.cacheName());
-                }
-            }
-        }
-
-        /** {@inheritDoc} */
-        @Override public void delete(Object key) throws CacheWriterException {
-            deleteCnt.incrementAndGet();
-
-            checkSession();
-        }
-
-        /** {@inheritDoc} */
-        @Override public void sessionEnd(boolean commit) {
-            assertNull(ses.attachment());
-        }
-
-        /**
-         */
-        private void checkSession() {
-            Session hibSes = ses.attachment();
-
-            assertNotNull(hibSes);
-
-            assertTrue(hibSes.isOpen());
-
-            Transaction tx = hibSes.getTransaction();
-
-            assertNotNull(tx);
-
-            if (ses.isWithinTransaction())
-                assertTrue(tx.isActive());
-            else
-                assertFalse(tx.isActive());
-
-            verifySameInstance(hibSes);
-        }
-
-        /**
-         * @param hibSes Session.
-         */
-        private void verifySameInstance(Session hibSes) {
-            Map<String, Session> props = ses.properties();
-
-            Session sesConn = props.get(SES_CONN_KEY);
-
-            if (sesConn == null)
-                props.put(SES_CONN_KEY, hibSes);
-            else {
-                assertSame(hibSes, sesConn);
-
-                reuseCnt.incrementAndGet();
-            }
-        }
-    }
-
-    /**
-     */
-    @Entity
-    @Table(name = "Table1")
-    private static class Table1 implements Serializable {
-        /** */
-        @Id
-        @GeneratedValue(strategy = GenerationType.IDENTITY)
-        @Column(name = "id")
-        private Integer id;
-
-        /** */
-        @Column(name = "key")
-        private int key;
-
-        /** */
-        @Column(name = "value")
-        private int value;
-
-        /**
-         * @param key Key.
-         * @param value Value.
-         */
-        private Table1(int key, int value) {
-            this.key = key;
-            this.value = value;
-        }
-    }
-
-    /**
-     */
-    @Entity
-    @Table(name = "Table2")
-    private static class Table2 implements Serializable {
-        /** */
-        @Id
-        @GeneratedValue(strategy = GenerationType.IDENTITY)
-        @Column(name = "id")
-        private Integer id;
-
-        /** */
-        @Column(name = "key")
-        private int key;
-
-        /** */
-        @Column(name = "value")
-        private int value;
-
-        /**
-         * @param key Key.
-         * @param value Value.
-         */
-        private Table2(int key, int value) {
-            this.key = key;
-            this.value = value;
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml b/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml
deleted file mode 100644
index 3822b31..0000000
--- a/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml
+++ /dev/null
@@ -1,42 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one or more
-  contributor license agreements.  See the NOTICE file distributed with
-  this work for additional information regarding copyright ownership.
-  The ASF licenses this file to You under the Apache License, Version 2.0
-  (the "License"); you may not use this file except in compliance with
-  the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-
-
-<!DOCTYPE hibernate-configuration PUBLIC
-        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
-        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
-
-<hibernate-configuration>
-    <session-factory>
-        <!-- Show SQL. -->
-        <property name="show_sql">true</property>
-
-        <!-- Database connection settings (private in-memory database). -->
-        <property name="connection.url">jdbc:h2:mem:example;DB_CLOSE_DELAY=-1</property>
-
-        <!-- Only validate the database schema on startup in production mode. -->
-        <property name="hbm2ddl.auto">update</property>
-
-        <!-- H2 dialect. -->
-        <property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
-
-        <!-- Mappings. -->
-        <mapping resource="org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml"/>
-    </session-factory>
-</hibernate-configuration>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/package-info.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/package-info.java b/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/package-info.java
deleted file mode 100644
index 8af9886..0000000
--- a/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * <!-- Package description. -->
- * Contains internal tests or test related classes and interfaces.
- */
-package org.apache.ignite.cache.store.hibernate;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/test/java/org/apache/ignite/testsuites/IgniteBinaryHibernate5TestSuite.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/test/java/org/apache/ignite/testsuites/IgniteBinaryHibernate5TestSuite.java b/modules/hibernate5/src/test/java/org/apache/ignite/testsuites/IgniteBinaryHibernate5TestSuite.java
deleted file mode 100644
index d539511..0000000
--- a/modules/hibernate5/src/test/java/org/apache/ignite/testsuites/IgniteBinaryHibernate5TestSuite.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.testsuites;
-
-import junit.framework.TestSuite;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
-import org.apache.ignite.testframework.config.GridTestProperties;
-
-/**
- *
- */
-public class IgniteBinaryHibernate5TestSuite extends TestSuite {
-    /**
-     * @return Test suite.
-     * @throws Exception If failed.
-     */
-    public static TestSuite suite() throws Exception {
-        GridTestProperties.setProperty(GridTestProperties.MARSH_CLASS_NAME, BinaryMarshaller.class.getName());
-
-        return IgniteHibernate5TestSuite.suite();
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/test/java/org/apache/ignite/testsuites/IgniteHibernate5TestSuite.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/test/java/org/apache/ignite/testsuites/IgniteHibernate5TestSuite.java b/modules/hibernate5/src/test/java/org/apache/ignite/testsuites/IgniteHibernate5TestSuite.java
deleted file mode 100644
index 3d7c4ee..0000000
--- a/modules/hibernate5/src/test/java/org/apache/ignite/testsuites/IgniteHibernate5TestSuite.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.testsuites;
-
-import junit.framework.TestSuite;
-import org.apache.ignite.cache.hibernate.HibernateL2CacheConfigurationSelfTest;
-import org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest;
-import org.apache.ignite.cache.hibernate.HibernateL2CacheTransactionalSelfTest;
-import org.apache.ignite.cache.hibernate.HibernateL2CacheTransactionalUseSyncSelfTest;
-import org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreNodeRestartTest;
-import org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreSelfTest;
-import org.apache.ignite.cache.store.hibernate.CacheHibernateStoreFactorySelfTest;
-import org.apache.ignite.cache.store.hibernate.CacheHibernateStoreSessionListenerSelfTest;
-
-/**
- * Hibernate integration tests.
- */
-public class IgniteHibernate5TestSuite extends TestSuite {
-    /**
-     * @return Test suite.
-     * @throws Exception Thrown in case of the failure.
-     */
-    public static TestSuite suite() throws Exception {
-        TestSuite suite = new TestSuite("Hibernate5 Integration Test Suite");
-
-        // Hibernate L2 cache.
-        suite.addTestSuite(HibernateL2CacheSelfTest.class);
-        suite.addTestSuite(HibernateL2CacheTransactionalSelfTest.class);
-        suite.addTestSuite(HibernateL2CacheTransactionalUseSyncSelfTest.class);
-        suite.addTestSuite(HibernateL2CacheConfigurationSelfTest.class);
-
-        suite.addTestSuite(CacheHibernateBlobStoreSelfTest.class);
-
-        suite.addTestSuite(CacheHibernateBlobStoreNodeRestartTest.class);
-
-        suite.addTestSuite(CacheHibernateStoreSessionListenerSelfTest.class);
-
-        suite.addTestSuite(CacheHibernateStoreFactorySelfTest.class);
-
-        return suite;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/osgi-karaf/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/modules/osgi-karaf/src/main/resources/features.xml b/modules/osgi-karaf/src/main/resources/features.xml
index f6bdf2b..9846d97 100644
--- a/modules/osgi-karaf/src/main/resources/features.xml
+++ b/modules/osgi-karaf/src/main/resources/features.xml
@@ -110,7 +110,7 @@
             NOTE: Take into account that certain parts of Hibernate are offered under the LGPL license.]]>
         </details>
         <feature>hibernate</feature>
-        <bundle start="true">mvn:org.apache.ignite/ignite-hibernate/${project.version}</bundle>
+        <bundle start="true">mvn:org.apache.ignite/ignite-hibernate_4.2/${project.version}</bundle>
     </feature>
 
     <feature name="ignite-indexing" version="${project.version}" description="Apache Ignite :: Indexing">

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index e1bb73e..8a05342 100644
--- a/pom.xml
+++ b/pom.xml
@@ -91,6 +91,7 @@
         <module>modules/flink</module>
         <module>modules/kubernetes</module>
         <module>modules/zeromq</module>
+        <module>modules/hibernate-core</module>
     </modules>
 
     <profiles>
@@ -100,8 +101,8 @@
                 <module>examples</module>
                 <module>modules/benchmarks</module>
                 <module>modules/geospatial</module>
-                <module>modules/hibernate5</module>
-                <module>modules/hibernate</module>
+                <module>modules/hibernate-4.2</module>
+                <module>modules/hibernate-5.1</module>
                 <module>modules/schedule</module>
                 <module>modules/web-console/web-agent</module>
                 <module>modules/yardstick</module>
@@ -197,8 +198,8 @@
         <profile>
             <id>lgpl</id>
             <modules>
-                <module>modules/hibernate</module>
-                <module>modules/hibernate5</module>
+                <module>modules/hibernate-4.2</module>
+                <module>modules/hibernate-5.1</module>
                 <module>modules/geospatial</module>
                 <module>modules/schedule</module>
             </modules>


[02/16] ignite git commit: ignite-1794 Refactored hibernate modules, switched to hibernate 5.1

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java b/modules/hibernate5/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java
deleted file mode 100644
index f847c97..0000000
--- a/modules/hibernate5/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java
+++ /dev/null
@@ -1,1948 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.Callable;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.OneToMany;
-import javax.persistence.OneToOne;
-import javax.persistence.PersistenceException;
-import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.hibernate.ObjectNotFoundException;
-import org.hibernate.Query;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.Transaction;
-import org.hibernate.annotations.NaturalId;
-import org.hibernate.annotations.NaturalIdCache;
-import org.hibernate.boot.Metadata;
-import org.hibernate.boot.MetadataSources;
-import org.hibernate.boot.registry.StandardServiceRegistry;
-import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
-import org.hibernate.cache.spi.GeneralDataRegion;
-import org.hibernate.cache.spi.TransactionalDataRegion;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cfg.Environment;
-import org.hibernate.exception.ConstraintViolationException;
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.mapping.RootClass;
-import org.hibernate.stat.NaturalIdCacheStatistics;
-import org.hibernate.stat.SecondLevelCacheStatistics;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
-import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
-import static org.apache.ignite.cache.hibernate.HibernateRegionFactory.DFLT_ACCESS_TYPE_PROPERTY;
-import static org.apache.ignite.cache.hibernate.HibernateRegionFactory.IGNITE_INSTANCE_NAME_PROPERTY;
-import static org.apache.ignite.cache.hibernate.HibernateRegionFactory.REGION_CACHE_PROPERTY;
-import static org.hibernate.cfg.Environment.CACHE_REGION_FACTORY;
-import static org.hibernate.cfg.Environment.GENERATE_STATISTICS;
-import static org.hibernate.cfg.Environment.HBM2DDL_AUTO;
-import static org.hibernate.cfg.Environment.RELEASE_CONNECTIONS;
-import static org.hibernate.cfg.Environment.USE_QUERY_CACHE;
-import static org.hibernate.cfg.Environment.USE_SECOND_LEVEL_CACHE;
-
-/**
- *
- * Tests Hibernate L2 cache.
- */
-public class HibernateL2CacheSelfTest extends GridCommonAbstractTest {
-    /** */
-    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
-
-    /** */
-    public static final String CONNECTION_URL = "jdbc:h2:mem:example;DB_CLOSE_DELAY=-1";
-
-    /** */
-    public static final String ENTITY_NAME = Entity.class.getName();
-
-    /** */
-    public static final String ENTITY2_NAME = Entity2.class.getName();
-
-    /** */
-    public static final String VERSIONED_ENTITY_NAME = VersionedEntity.class.getName();
-
-    /** */
-    public static final String CHILD_ENTITY_NAME = ChildEntity.class.getName();
-
-    /** */
-    public static final String PARENT_ENTITY_NAME = ParentEntity.class.getName();
-
-    /** */
-    public static final String CHILD_COLLECTION_REGION = ENTITY_NAME + ".children";
-
-    /** */
-    public static final String NATURAL_ID_REGION =
-        "org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest$Entity##NaturalId";
-
-    /** */
-    public static final String NATURAL_ID_REGION2 =
-        "org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest$Entity2##NaturalId";
-
-    /** */
-    private SessionFactory sesFactory1;
-
-    /** */
-    private SessionFactory sesFactory2;
-
-    /**
-     * First Hibernate test entity.
-     */
-    @javax.persistence.Entity
-    @NaturalIdCache
-    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
-    public static class Entity {
-        /** */
-        private int id;
-
-        /** */
-        private String name;
-
-        /** */
-        private Collection<ChildEntity> children;
-
-        /**
-         * Default constructor required by Hibernate.
-         */
-        public Entity() {
-            // No-op.
-        }
-
-        /**
-         * @param id ID.
-         * @param name Name.
-         */
-        public Entity(int id, String name) {
-            this.id = id;
-            this.name = name;
-        }
-
-        /**
-         * @return ID.
-         */
-        @Id
-        public int getId() {
-            return id;
-        }
-
-        /**
-         * @param id ID.
-         */
-        public void setId(int id) {
-            this.id = id;
-        }
-
-        /**
-         * @return Name.
-         */
-        @NaturalId(mutable = true)
-        public String getName() {
-            return name;
-        }
-
-        /**
-         * @param name Name.
-         */
-        public void setName(String name) {
-            this.name = name;
-        }
-
-        /**
-         * @return Children.
-         */
-        @OneToMany(cascade=javax.persistence.CascadeType.ALL, fetch=FetchType.LAZY)
-        @JoinColumn(name="ENTITY_ID")
-        public Collection<ChildEntity> getChildren() {
-            return children;
-        }
-
-        /**
-         * @param children Children.
-         */
-        public void setChildren(Collection<ChildEntity> children) {
-            this.children = children;
-        }
-    }
-
-    /**
-     * Second Hibernate test entity.
-     */
-    @javax.persistence.Entity
-    @NaturalIdCache
-    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
-    public static class Entity2 {
-        /** */
-        private int id;
-
-        /** */
-        private String name;
-
-        /** */
-        private Collection<ChildEntity> children;
-
-        /**
-         * Default constructor required by Hibernate.
-         */
-        public Entity2() {
-            // No-op.
-        }
-
-        /**
-         * @param id ID.
-         * @param name Name.
-         */
-        public Entity2(int id, String name) {
-            this.id = id;
-            this.name = name;
-        }
-
-        /**
-         * @return ID.
-         */
-        @Id
-        public int getId() {
-            return id;
-        }
-
-        /**
-         * @param id ID.
-         */
-        public void setId(int id) {
-            this.id = id;
-        }
-
-        /**
-         * @return Name.
-         */
-        @NaturalId(mutable = true)
-        public String getName() {
-            return name;
-        }
-
-        /**
-         * @param name Name.
-         */
-        public void setName(String name) {
-            this.name = name;
-        }
-    }
-
-    /**
-     * Hibernate child entity referenced by {@link Entity}.
-     */
-    @javax.persistence.Entity
-    @SuppressWarnings("PublicInnerClass")
-    public static class ChildEntity {
-        /** */
-        private int id;
-
-        /**
-         * Default constructor required by Hibernate.
-         */
-        public ChildEntity() {
-            // No-op.
-        }
-
-        /**
-         * @param id ID.
-         */
-        public ChildEntity(int id) {
-            this.id = id;
-        }
-
-        /**
-         * @return ID.
-         */
-        @Id
-        @GeneratedValue
-        public int getId() {
-            return id;
-        }
-
-        /**
-         * @param id ID.
-         */
-        public void setId(int id) {
-            this.id = id;
-        }
-    }
-
-    /**
-     * Hibernate entity referencing {@link Entity}.
-     */
-    @javax.persistence.Entity
-    @SuppressWarnings("PublicInnerClass")
-    public static class ParentEntity {
-        /** */
-        private int id;
-
-        /** */
-        private Entity entity;
-
-        /**
-         * Default constructor required by Hibernate.
-         */
-        public ParentEntity() {
-            // No-op.
-        }
-
-        /**
-         * @param id ID.
-         * @param entity Referenced entity.
-         */
-        public ParentEntity(int id, Entity entity) {
-            this.id = id;
-            this.entity = entity;
-        }
-
-        /**
-         * @return ID.
-         */
-        @Id
-        public int getId() {
-            return id;
-        }
-
-        /**
-         * @param id ID.
-         */
-        public void setId(int id) {
-            this.id = id;
-        }
-
-        /**
-         * @return Referenced entity.
-         */
-        @OneToOne
-        public Entity getEntity() {
-            return entity;
-        }
-
-        /**
-         * @param entity Referenced entity.
-         */
-        public void setEntity(Entity entity) {
-            this.entity = entity;
-        }
-    }
-
-    /**
-     * Hibernate entity.
-     */
-    @javax.persistence.Entity
-    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
-    public static class VersionedEntity {
-        /** */
-        private int id;
-
-        /** */
-        private long ver;
-
-        /**
-         * Default constructor required by Hibernate.
-         */
-        public VersionedEntity() {
-        }
-
-        /**
-         * @param id ID.
-         */
-        public VersionedEntity(int id) {
-            this.id = id;
-        }
-
-        /**
-         * @return ID.
-         */
-        @Id
-        public int getId() {
-            return id;
-        }
-
-        /**
-         * @param id ID.
-         */
-        public void setId(int id) {
-            this.id = id;
-        }
-
-        /**
-         * @return Version.
-         */
-        @javax.persistence.Version
-        public long getVersion() {
-            return ver;
-        }
-
-        /**
-         * @param ver Version.
-         */
-        public void setVersion(long ver) {
-            this.ver = ver;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
-
-        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
-
-        discoSpi.setIpFinder(IP_FINDER);
-
-        cfg.setDiscoverySpi(discoSpi);
-
-        cfg.setCacheConfiguration(generalRegionConfiguration("org.hibernate.cache.spi.UpdateTimestampsCache"),
-            generalRegionConfiguration("org.hibernate.cache.internal.StandardQueryCache"),
-            transactionalRegionConfiguration(ENTITY_NAME),
-            transactionalRegionConfiguration(ENTITY2_NAME),
-            transactionalRegionConfiguration(VERSIONED_ENTITY_NAME),
-            transactionalRegionConfiguration(PARENT_ENTITY_NAME),
-            transactionalRegionConfiguration(CHILD_ENTITY_NAME),
-            transactionalRegionConfiguration(CHILD_COLLECTION_REGION),
-            transactionalRegionConfiguration(NATURAL_ID_REGION),
-            transactionalRegionConfiguration(NATURAL_ID_REGION2));
-
-        return cfg;
-    }
-
-    /**
-     * @param regionName Region name.
-     * @return Cache configuration for {@link GeneralDataRegion}.
-     */
-    private CacheConfiguration generalRegionConfiguration(String regionName) {
-        CacheConfiguration cfg = new CacheConfiguration();
-
-        cfg.setName(regionName);
-
-        cfg.setCacheMode(PARTITIONED);
-
-        cfg.setAtomicityMode(ATOMIC);
-
-        cfg.setWriteSynchronizationMode(FULL_SYNC);
-
-        cfg.setBackups(1);
-
-        cfg.setAffinity(new RendezvousAffinityFunction(false, 10));
-
-        return cfg;
-    }
-
-    /**
-     * @param regionName Region name.
-     * @return Cache configuration for {@link TransactionalDataRegion}.
-     */
-    protected CacheConfiguration transactionalRegionConfiguration(String regionName) {
-        CacheConfiguration cfg = new CacheConfiguration();
-
-        cfg.setName(regionName);
-
-        cfg.setCacheMode(PARTITIONED);
-
-        cfg.setAtomicityMode(TRANSACTIONAL);
-
-        cfg.setWriteSynchronizationMode(FULL_SYNC);
-
-        cfg.setBackups(1);
-
-        cfg.setAffinity(new RendezvousAffinityFunction(false, 10));
-
-        return cfg;
-    }
-
-    /**
-     * @return Hibernate registry builder.
-     */
-    protected StandardServiceRegistryBuilder registryBuilder() {
-        StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
-
-        builder.applySetting("hibernate.connection.url", CONNECTION_URL);
-
-        return builder;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        startGrids(2);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        stopAllGrids();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        cleanup();
-    }
-
-    /**
-     * @return Hibernate L2 cache access types to test.
-     */
-    protected AccessType[] accessTypes() {
-        return new AccessType[]{AccessType.READ_ONLY, AccessType.NONSTRICT_READ_WRITE, AccessType.READ_WRITE};
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testCollectionCache() throws Exception {
-        for (AccessType accessType : accessTypes())
-            testCollectionCache(accessType);
-    }
-
-    /**
-     * @param accessType Cache access type.
-     * @throws Exception If failed.
-     */
-    @SuppressWarnings("unchecked")
-    private void testCollectionCache(AccessType accessType) throws Exception {
-        createSessionFactories(accessType);
-
-        Map<Integer, Integer> idToChildCnt = new HashMap<>();
-
-        try {
-            Session ses = sesFactory1.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                for (int i = 0; i < 3; i++) {
-                    Entity e = new Entity(i, "name-" + i);
-
-                    Collection<ChildEntity> children = new ArrayList<>();
-
-                    for (int j = 0; j < 3; j++)
-                        children.add(new ChildEntity());
-
-                    e.setChildren(children);
-
-                    idToChildCnt.put(e.getId(), e.getChildren().size());
-
-                    ses.save(e);
-                }
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            // Load children, this should populate cache.
-
-            ses = sesFactory1.openSession();
-
-            try {
-                List<Entity> list = ses.createCriteria(ENTITY_NAME).list();
-
-                assertEquals(idToChildCnt.size(), list.size());
-
-                for (Entity e : list)
-                    assertEquals((int)idToChildCnt.get(e.getId()), e.getChildren().size());
-            }
-            finally {
-                ses.close();
-            }
-
-            assertCollectionCache(sesFactory2, idToChildCnt, 3, 0);
-            assertCollectionCache(sesFactory1, idToChildCnt, 3, 0);
-
-            if (accessType == AccessType.READ_ONLY)
-                return;
-
-            // Update children for one entity.
-
-            ses = sesFactory1.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                Entity e1 = (Entity)ses.load(Entity.class, 1);
-
-                e1.getChildren().remove(e1.getChildren().iterator().next());
-
-                ses.update(e1);
-
-                idToChildCnt.put(e1.getId(), e1.getChildren().size());
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertCollectionCache(sesFactory2, idToChildCnt, 2, 1); // After update collection cache entry is removed.
-            assertCollectionCache(sesFactory1, idToChildCnt, 3, 0); // 'assertCollectionCache' loads children in cache.
-
-            // Update children for the same entity using another SessionFactory.
-
-            ses = sesFactory2.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                Entity e1 = (Entity)ses.load(Entity.class, 1);
-
-                e1.getChildren().remove(e1.getChildren().iterator().next());
-
-                ses.update(e1);
-
-                idToChildCnt.put(e1.getId(), e1.getChildren().size());
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertCollectionCache(sesFactory2, idToChildCnt, 2, 1); // After update collection cache entry is removed.
-            assertCollectionCache(sesFactory1, idToChildCnt, 3, 0); // 'assertCollectionCache' loads children in cache.
-        }
-        finally {
-            cleanup();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testEntityCache() throws Exception {
-        for (AccessType accessType : accessTypes())
-            testEntityCache(accessType);
-    }
-
-    /**
-     * @param accessType Cache access type.
-     * @throws Exception If failed.
-     */
-    private void testEntityCache(AccessType accessType) throws Exception {
-        createSessionFactories(accessType);
-
-        Map<Integer, String> idToName = new HashMap<>();
-
-        try {
-            Session ses = sesFactory1.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                for (int i = 0; i < 2; i++) {
-                    String name = "name-" + i;
-
-                    ses.save(new Entity(i, name));
-
-                    idToName.put(i, name);
-                }
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName, 100);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName, 100);
-
-            if (accessType == AccessType.READ_ONLY)
-                return;
-
-            ses = sesFactory1.openSession();
-
-            try {
-                // Updates and inserts in single transaction.
-
-                Transaction tx = ses.beginTransaction();
-
-                Entity e0 = (Entity)ses.load(Entity.class, 0);
-
-                e0.setName("name-0-changed1");
-
-                ses.update(e0);
-
-                idToName.put(0, e0.getName());
-
-                ses.save(new Entity(2, "name-2"));
-
-                idToName.put(2, "name-2");
-
-                Entity e1 = (Entity)ses.load(Entity.class, 1);
-
-                e1.setName("name-1-changed1");
-
-                ses.update(e1);
-
-                idToName.put(1, e1.getName());
-
-                ses.save(new Entity(3, "name-3"));
-
-                idToName.put(3, "name-3");
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName);
-
-            ses = sesFactory1.openSession();
-
-            try {
-                // Updates, inserts and deletes in single transaction.
-
-                Transaction tx = ses.beginTransaction();
-
-                ses.save(new Entity(4, "name-4"));
-
-                idToName.put(4, "name-4");
-
-                Entity e0 = (Entity)ses.load(Entity.class, 0);
-
-                e0.setName("name-0-changed2");
-
-                ses.update(e0);
-
-                idToName.put(e0.getId(), e0.getName());
-
-                ses.delete(ses.load(Entity.class, 1));
-
-                idToName.remove(1);
-
-                Entity e2 = (Entity)ses.load(Entity.class, 2);
-
-                e2.setName("name-2-changed1");
-
-                ses.update(e2);
-
-                idToName.put(e2.getId(), e2.getName());
-
-                ses.delete(ses.load(Entity.class, 3));
-
-                idToName.remove(3);
-
-                ses.save(new Entity(5, "name-5"));
-
-                idToName.put(5, "name-5");
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName, 1, 3);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName, 1, 3);
-
-            // Try to update the same entity using another SessionFactory.
-
-            ses = sesFactory2.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                Entity e0 = (Entity)ses.load(Entity.class, 0);
-
-                e0.setName("name-0-changed3");
-
-                ses.update(e0);
-
-                idToName.put(e0.getId(), e0.getName());
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName);
-        }
-        finally {
-            cleanup();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testTwoEntitiesSameCache() throws Exception {
-        for (AccessType accessType : accessTypes())
-            testTwoEntitiesSameCache(accessType);
-    }
-
-    /**
-     * @param accessType Cache access type.
-     * @throws Exception If failed.
-     */
-    private void testTwoEntitiesSameCache(AccessType accessType) throws Exception {
-        createSessionFactories(accessType);
-
-        try {
-            Session ses = sesFactory1.openSession();
-
-            Map<Integer, String> idToName1 = new HashMap<>();
-            Map<Integer, String> idToName2 = new HashMap<>();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                for (int i = 0; i < 2; i++) {
-                    String name = "name-" + i;
-
-                    ses.save(new Entity(i, name));
-                    ses.save(new Entity2(i, name));
-
-                    idToName1.put(i, name);
-                    idToName2.put(i, name);
-                }
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName1, 100);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName1, 100);
-
-            assertEntityCache(ENTITY2_NAME, sesFactory2, idToName2, 100);
-            assertEntityCache(ENTITY2_NAME, sesFactory1, idToName2, 100);
-
-            if (accessType == AccessType.READ_ONLY)
-                return;
-
-            ses = sesFactory1.openSession();
-
-            try {
-                // Updates both entities in single transaction.
-
-                Transaction tx = ses.beginTransaction();
-
-                Entity e = (Entity)ses.load(Entity.class, 0);
-
-                e.setName("name-0-changed1");
-
-                ses.update(e);
-
-                Entity2 e2 = (Entity2)ses.load(Entity2.class, 0);
-
-                e2.setName("name-e2-0-changed1");
-
-                ses.update(e2);
-
-                idToName1.put(0, e.getName());
-                idToName2.put(0, e2.getName());
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName1, 100);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName1, 100);
-
-            assertEntityCache(ENTITY2_NAME, sesFactory2, idToName2, 100);
-            assertEntityCache(ENTITY2_NAME, sesFactory1, idToName2, 100);
-
-            ses = sesFactory1.openSession();
-
-            try {
-                // Remove entity1 and insert entity2 in single transaction.
-
-                Transaction tx = ses.beginTransaction();
-
-                Entity e = (Entity)ses.load(Entity.class, 0);
-
-                ses.delete(e);
-
-                Entity2 e2 = new Entity2(2, "name-2");
-
-                ses.save(e2);
-
-                idToName1.remove(0);
-                idToName2.put(2, e2.getName());
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName1, 0, 100);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName1, 0, 100);
-
-            assertEntityCache(ENTITY2_NAME, sesFactory2, idToName2, 100);
-            assertEntityCache(ENTITY2_NAME, sesFactory1, idToName2, 100);
-
-            ses = sesFactory1.openSession();
-
-            Transaction tx = ses.beginTransaction();
-
-            try {
-                // Update, remove, insert in single transaction, transaction fails.
-
-                Entity e = (Entity)ses.load(Entity.class, 1);
-
-                e.setName("name-1-changed1");
-
-                ses.update(e); // Valid update.
-
-                ses.save(new Entity(2, "name-2")); // Valid insert.
-
-                ses.delete(ses.load(Entity2.class, 0)); // Valid delete.
-
-                Entity2 e2 = (Entity2)ses.load(Entity2.class, 1);
-
-                e2.setName("name-2");  // Invalid update, not-unique name.
-
-                ses.update(e2);
-
-                tx.commit();
-
-                fail("Commit must fail.");
-            }
-            catch (PersistenceException e) {
-                log.info("Expected exception: " + e);
-
-                tx.rollback();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName1, 0, 2, 100);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName1, 0, 2, 100);
-
-            assertEntityCache(ENTITY2_NAME, sesFactory2, idToName2, 100);
-            assertEntityCache(ENTITY2_NAME, sesFactory1, idToName2, 100);
-
-            ses = sesFactory2.openSession();
-
-            try {
-                // Update, remove, insert in single transaction.
-
-                tx = ses.beginTransaction();
-
-                Entity e = (Entity)ses.load(Entity.class, 1);
-
-                e.setName("name-1-changed1");
-
-                ses.update(e);
-
-                idToName1.put(1, e.getName());
-
-                ses.save(new Entity(2, "name-2"));
-
-                idToName1.put(2, "name-2");
-
-                ses.delete(ses.load(Entity2.class, 0));
-
-                idToName2.remove(0);
-
-                Entity2 e2 = (Entity2)ses.load(Entity2.class, 1);
-
-                e2.setName("name-e2-2-changed");
-
-                ses.update(e2);
-
-                idToName2.put(1, e2.getName());
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName1, 0, 100);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName1, 0, 100);
-
-            assertEntityCache(ENTITY2_NAME, sesFactory2, idToName2, 0, 100);
-            assertEntityCache(ENTITY2_NAME, sesFactory1, idToName2, 0, 100);
-        }
-        finally {
-            cleanup();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testVersionedEntity() throws Exception {
-        for (AccessType accessType : accessTypes())
-            testVersionedEntity(accessType);
-    }
-
-    /**
-     * @param accessType Cache access type.
-     * @throws Exception If failed.
-     */
-    private void testVersionedEntity(AccessType accessType) throws Exception {
-        createSessionFactories(accessType);
-
-        try {
-            Session ses = sesFactory1.openSession();
-
-            VersionedEntity e0 = new VersionedEntity(0);
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                ses.save(e0);
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            ses = sesFactory1.openSession();
-
-            long ver;
-
-            try {
-                ver = ((VersionedEntity)ses.load(VersionedEntity.class, 0)).getVersion();
-            }
-            finally {
-                ses.close();
-            }
-
-            SecondLevelCacheStatistics stats1 =
-                sesFactory1.getStatistics().getSecondLevelCacheStatistics(VERSIONED_ENTITY_NAME);
-            SecondLevelCacheStatistics stats2 =
-                sesFactory2.getStatistics().getSecondLevelCacheStatistics(VERSIONED_ENTITY_NAME);
-
-            assertEquals(1, stats1.getElementCountInMemory());
-            assertEquals(1, stats2.getElementCountInMemory());
-
-            ses = sesFactory2.openSession();
-
-            try {
-                assertEquals(ver, ((VersionedEntity)ses.load(VersionedEntity.class, 0)).getVersion());
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEquals(1, stats2.getElementCountInMemory());
-            assertEquals(1, stats2.getHitCount());
-
-            if (accessType == AccessType.READ_ONLY)
-                return;
-
-            e0.setVersion(ver - 1);
-
-            ses = sesFactory1.openSession();
-
-            Transaction tx = ses.beginTransaction();
-
-            try {
-                ses.update(e0);
-
-                tx.commit();
-
-                fail("Commit must fail.");
-            }
-            catch (PersistenceException e) {
-                log.info("Expected exception: " + e);
-            }
-            finally {
-                tx.rollback();
-
-                ses.close();
-            }
-
-            sesFactory1.getStatistics().clear();
-
-            stats1 = sesFactory1.getStatistics().getSecondLevelCacheStatistics(VERSIONED_ENTITY_NAME);
-
-            ses = sesFactory1.openSession();
-
-            try {
-                assertEquals(ver, ((VersionedEntity)ses.load(VersionedEntity.class, 0)).getVersion());
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEquals(1, stats1.getElementCountInMemory());
-            assertEquals(1, stats1.getHitCount());
-            assertEquals(1, stats2.getElementCountInMemory());
-            assertEquals(1, stats2.getHitCount());
-        }
-        finally {
-            cleanup();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testNaturalIdCache() throws Exception {
-        fail("https://issues.apache.org/jira/browse/IGNITE-1084");
-
-        for (AccessType accessType : accessTypes())
-            testNaturalIdCache(accessType);
-    }
-
-    /**
-     * @param accessType Cache access type.
-     * @throws Exception If failed.
-     */
-    private void testNaturalIdCache(AccessType accessType) throws Exception {
-        createSessionFactories(accessType);
-
-        Map<String, Integer> nameToId = new HashMap<>();
-
-        try {
-            Session ses = sesFactory1.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                for (int i = 0; i < 3; i++) {
-                    String name = "name-" + i;
-
-                    ses.save(new Entity(i, name));
-
-                    nameToId.put(name, i);
-                }
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            ses = sesFactory1.openSession();
-
-            try {
-                for (Map.Entry<String, Integer> e : nameToId.entrySet())
-                    ((Entity)ses.bySimpleNaturalId(Entity.class).load(e.getKey())).getId();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertNaturalIdCache(sesFactory2, nameToId, "name-100");
-            assertNaturalIdCache(sesFactory1, nameToId, "name-100");
-
-            if (accessType == AccessType.READ_ONLY)
-                return;
-
-            // Update naturalId.
-
-            ses = sesFactory1.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                Entity e1 = (Entity)ses.load(Entity.class, 1);
-
-                nameToId.remove(e1.getName());
-
-                e1.setName("name-1-changed1");
-
-                nameToId.put(e1.getName(), e1.getId());
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertNaturalIdCache(sesFactory2, nameToId, "name-1");
-            assertNaturalIdCache(sesFactory1, nameToId, "name-1");
-
-            // Update entity using another SessionFactory.
-
-            ses = sesFactory2.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                Entity e1 = (Entity)ses.load(Entity.class, 1);
-
-                nameToId.remove(e1.getName());
-
-                e1.setName("name-1-changed2");
-
-                nameToId.put(e1.getName(), e1.getId());
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertNaturalIdCache(sesFactory2, nameToId, "name-1-changed1");
-            assertNaturalIdCache(sesFactory1, nameToId, "name-1-changed1");
-
-            // Try invalid NaturalId update.
-
-            ses = sesFactory1.openSession();
-
-            Transaction tx = ses.beginTransaction();
-
-            try {
-                Entity e1 = (Entity)ses.load(Entity.class, 1);
-
-                e1.setName("name-0"); // Invalid update (duplicated name).
-
-                tx.commit();
-
-                fail("Commit must fail.");
-            }
-            catch (ConstraintViolationException e) {
-                log.info("Expected exception: " + e);
-
-                tx.rollback();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertNaturalIdCache(sesFactory2, nameToId);
-            assertNaturalIdCache(sesFactory1, nameToId);
-
-            // Delete entity.
-
-            ses = sesFactory2.openSession();
-
-            try {
-                tx = ses.beginTransaction();
-
-                Entity e2 = (Entity)ses.load(Entity.class, 2);
-
-                ses.delete(e2);
-
-                nameToId.remove(e2.getName());
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertNaturalIdCache(sesFactory2, nameToId, "name-2");
-            assertNaturalIdCache(sesFactory1, nameToId, "name-2");
-        }
-        finally {
-            cleanup();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testEntityCacheTransactionFails() throws Exception {
-        for (AccessType accessType : accessTypes())
-            testEntityCacheTransactionFails(accessType);
-    }
-
-    /**
-     * @param accessType Cache access type.
-     * @throws Exception If failed.
-     */
-    private void testEntityCacheTransactionFails(AccessType accessType) throws Exception {
-        createSessionFactories(accessType);
-
-        Map<Integer, String> idToName = new HashMap<>();
-
-        try {
-            Session ses = sesFactory1.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                for (int i = 0; i < 3; i++) {
-                    String name = "name-" + i;
-
-                    ses.save(new Entity(i, name));
-
-                    idToName.put(i, name);
-                }
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName, 100);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName, 100);
-
-            ses = sesFactory1.openSession();
-
-            Transaction tx = ses.beginTransaction();
-
-            try {
-                ses.save(new Entity(3, "name-3")); // Valid insert.
-
-                ses.save(new Entity(0, "name-0")); // Invalid insert (duplicated ID).
-
-                tx.commit();
-
-                fail("Commit must fail.");
-            }
-            catch (PersistenceException e) {
-                log.info("Expected exception: " + e);
-
-                tx.rollback();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName, 3);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName, 3);
-
-            if (accessType == AccessType.READ_ONLY)
-                return;
-
-            ses = sesFactory1.openSession();
-
-            tx = ses.beginTransaction();
-
-            try {
-                Entity e0 = (Entity)ses.load(Entity.class, 0);
-                Entity e1 = (Entity)ses.load(Entity.class, 1);
-
-                e0.setName("name-10"); // Valid update.
-                e1.setName("name-2"); // Invalid update (violates unique constraint).
-
-                ses.update(e0);
-                ses.update(e1);
-
-                tx.commit();
-
-                fail("Commit must fail.");
-            }
-            catch (PersistenceException e) {
-                log.info("Expected exception: " + e);
-
-                tx.rollback();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName);
-
-            ses = sesFactory1.openSession();
-
-            try {
-                // Create parent entity referencing Entity with ID = 0.
-
-                tx = ses.beginTransaction();
-
-                ses.save(new ParentEntity(0, (Entity) ses.load(Entity.class, 0)));
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            ses = sesFactory1.openSession();
-
-            tx = ses.beginTransaction();
-
-            try {
-                ses.save(new Entity(3, "name-3")); // Valid insert.
-
-                Entity e1 = (Entity)ses.load(Entity.class, 1);
-
-                e1.setName("name-10"); // Valid update.
-
-                ses.delete(ses.load(Entity.class, 0)); // Invalid delete (there is a parent entity referencing it).
-
-                tx.commit();
-
-                fail("Commit must fail.");
-            }
-            catch (PersistenceException e) {
-                log.info("Expected exception: " + e);
-
-                tx.rollback();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName, 3);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName, 3);
-
-            ses = sesFactory1.openSession();
-
-            tx = ses.beginTransaction();
-
-            try {
-                ses.delete(ses.load(Entity.class, 1)); // Valid delete.
-
-                idToName.remove(1);
-
-                ses.delete(ses.load(Entity.class, 0)); // Invalid delete (there is a parent entity referencing it).
-
-                tx.commit();
-
-                fail("Commit must fail.");
-            }
-            catch (PersistenceException e) {
-                log.info("Expected exception: " + e);
-
-                tx.rollback();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName);
-        }
-        finally {
-            cleanup();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testQueryCache() throws Exception {
-        for (AccessType accessType : accessTypes())
-            testQueryCache(accessType);
-    }
-
-    /**
-     * @param accessType Cache access type.
-     * @throws Exception If failed.
-     */
-    private void testQueryCache(AccessType accessType) throws Exception {
-        createSessionFactories(accessType);
-
-        try {
-            Session ses = sesFactory1.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                for (int i = 0; i < 5; i++)
-                    ses.save(new Entity(i, "name-" + i));
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            // Run some queries.
-
-            ses = sesFactory1.openSession();
-
-            try {
-                Query qry1 = ses.createQuery("from " + ENTITY_NAME + " where id > 2");
-
-                qry1.setCacheable(true);
-
-                assertEquals(2, qry1.list().size());
-
-                Query qry2 = ses.createQuery("from " + ENTITY_NAME + " where name = 'name-0'");
-
-                qry2.setCacheable(true);
-
-                assertEquals(1, qry2.list().size());
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEquals(0, sesFactory1.getStatistics().getQueryCacheHitCount());
-            assertEquals(2, sesFactory1.getStatistics().getQueryCacheMissCount());
-            assertEquals(2, sesFactory1.getStatistics().getQueryCachePutCount());
-
-            // Run queries using another SessionFactory.
-
-            ses = sesFactory2.openSession();
-
-            try {
-                Query qry1 = ses.createQuery("from " + ENTITY_NAME + " where id > 2");
-
-                qry1.setCacheable(true);
-
-                assertEquals(2, qry1.list().size());
-
-                Query qry2 = ses.createQuery("from " + ENTITY_NAME + " where name = 'name-0'");
-
-                qry2.setCacheable(true);
-
-                assertEquals(1, qry2.list().size());
-
-                Query qry3 = ses.createQuery("from " + ENTITY_NAME + " where id > 1");
-
-                qry3.setCacheable(true);
-
-                assertEquals(3, qry3.list().size());
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEquals(2, sesFactory2.getStatistics().getQueryCacheHitCount());
-            assertEquals(1, sesFactory2.getStatistics().getQueryCacheMissCount());
-            assertEquals(1, sesFactory2.getStatistics().getQueryCachePutCount());
-
-            // Update entity, it should invalidate query cache.
-
-            ses = sesFactory1.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                ses.save(new Entity(5, "name-5"));
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            // Run queries.
-
-            ses = sesFactory1.openSession();
-
-            sesFactory1.getStatistics().clear();
-
-            try {
-                Query qry1 = ses.createQuery("from " + ENTITY_NAME + " where id > 2");
-
-                qry1.setCacheable(true);
-
-                assertEquals(3, qry1.list().size());
-
-                Query qry2 = ses.createQuery("from " + ENTITY_NAME + " where name = 'name-0'");
-
-                qry2.setCacheable(true);
-
-                assertEquals(1, qry2.list().size());
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEquals(0, sesFactory1.getStatistics().getQueryCacheHitCount());
-            assertEquals(2, sesFactory1.getStatistics().getQueryCacheMissCount());
-            assertEquals(2, sesFactory1.getStatistics().getQueryCachePutCount());
-
-            // Clear query cache using another SessionFactory.
-
-            sesFactory2.getCache().evictDefaultQueryRegion();
-
-            ses = sesFactory1.openSession();
-
-            // Run queries again.
-
-            sesFactory1.getStatistics().clear();
-
-            try {
-                Query qry1 = ses.createQuery("from " + ENTITY_NAME + " where id > 2");
-
-                qry1.setCacheable(true);
-
-                assertEquals(3, qry1.list().size());
-
-                Query qry2 = ses.createQuery("from " + ENTITY_NAME + " where name = 'name-0'");
-
-                qry2.setCacheable(true);
-
-                assertEquals(1, qry2.list().size());
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEquals(0, sesFactory1.getStatistics().getQueryCacheHitCount());
-            assertEquals(2, sesFactory1.getStatistics().getQueryCacheMissCount());
-            assertEquals(2, sesFactory1.getStatistics().getQueryCachePutCount());
-        }
-        finally {
-            cleanup();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testRegionClear() throws Exception {
-        for (AccessType accessType : accessTypes())
-            testRegionClear(accessType);
-    }
-
-    /**
-     * @param accessType Cache access type.
-     * @throws Exception If failed.
-     */
-    private void testRegionClear(AccessType accessType) throws Exception {
-        createSessionFactories(accessType);
-
-        try {
-            final int ENTITY_CNT = 100;
-
-            Session ses = sesFactory1.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                for (int i = 0; i < ENTITY_CNT; i++) {
-                    Entity e = new Entity(i, "name-" + i);
-
-                    Collection<ChildEntity> children = new ArrayList<>();
-
-                    for (int j = 0; j < 3; j++)
-                        children.add(new ChildEntity());
-
-                    e.setChildren(children);
-
-                    ses.save(e);
-                }
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            loadEntities(sesFactory2, ENTITY_CNT);
-
-            SecondLevelCacheStatistics stats1 = sesFactory1.getStatistics().getSecondLevelCacheStatistics(ENTITY_NAME);
-            SecondLevelCacheStatistics stats2 = sesFactory2.getStatistics().getSecondLevelCacheStatistics(ENTITY_NAME);
-
-            NaturalIdCacheStatistics idStats1 =
-                sesFactory1.getStatistics().getNaturalIdCacheStatistics(NATURAL_ID_REGION);
-            NaturalIdCacheStatistics idStats2 =
-                sesFactory2.getStatistics().getNaturalIdCacheStatistics(NATURAL_ID_REGION);
-
-            SecondLevelCacheStatistics colStats1 =
-                sesFactory1.getStatistics().getSecondLevelCacheStatistics(CHILD_COLLECTION_REGION);
-            SecondLevelCacheStatistics colStats2 =
-                sesFactory2.getStatistics().getSecondLevelCacheStatistics(CHILD_COLLECTION_REGION);
-
-            assertEquals(ENTITY_CNT, stats1.getElementCountInMemory());
-            assertEquals(ENTITY_CNT, stats2.getElementCountInMemory());
-
-            assertEquals(ENTITY_CNT, idStats1.getElementCountInMemory());
-            assertEquals(ENTITY_CNT, idStats2.getElementCountInMemory());
-
-            assertEquals(ENTITY_CNT, colStats1.getElementCountInMemory());
-            assertEquals(ENTITY_CNT, colStats2.getElementCountInMemory());
-
-            // Test cache is cleared after update query.
-
-            ses = sesFactory1.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                ses.createQuery("delete from " + ENTITY_NAME + " where name='no such name'").executeUpdate();
-
-                ses.createQuery("delete from " + ChildEntity.class.getName() + " where id=-1").executeUpdate();
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEquals(0, stats1.getElementCountInMemory());
-            assertEquals(0, stats2.getElementCountInMemory());
-
-            assertEquals(0, idStats1.getElementCountInMemory());
-            assertEquals(0, idStats2.getElementCountInMemory());
-
-            assertEquals(0, colStats1.getElementCountInMemory());
-            assertEquals(0, colStats2.getElementCountInMemory());
-
-            // Load some data in cache.
-
-            loadEntities(sesFactory1, 10);
-
-            assertEquals(10, stats1.getElementCountInMemory());
-            assertEquals(10, stats2.getElementCountInMemory());
-            assertEquals(10, idStats1.getElementCountInMemory());
-            assertEquals(10, idStats2.getElementCountInMemory());
-
-            // Test evictAll method.
-
-            sesFactory2.getCache().evictEntityRegion(ENTITY_NAME);
-
-            assertEquals(0, stats1.getElementCountInMemory());
-            assertEquals(0, stats2.getElementCountInMemory());
-
-            sesFactory2.getCache().evictNaturalIdRegion(ENTITY_NAME);
-
-            assertEquals(0, idStats1.getElementCountInMemory());
-            assertEquals(0, idStats2.getElementCountInMemory());
-
-            sesFactory2.getCache().evictCollectionRegion(CHILD_COLLECTION_REGION);
-
-            assertEquals(0, colStats1.getElementCountInMemory());
-            assertEquals(0, colStats2.getElementCountInMemory());
-        }
-        finally {
-            cleanup();
-        }
-    }
-
-    /**
-     * @param sesFactory Session factory.
-     * @param nameToId Name-ID mapping.
-     * @param absentNames Absent entities' names.
-     */
-    private void assertNaturalIdCache(SessionFactory sesFactory, Map<String, Integer> nameToId, String... absentNames) {
-        sesFactory.getStatistics().clear();
-
-        NaturalIdCacheStatistics stats =
-            sesFactory.getStatistics().getNaturalIdCacheStatistics(NATURAL_ID_REGION);
-
-        long hitBefore = stats.getHitCount();
-
-        long missBefore = stats.getMissCount();
-
-        final Session ses = sesFactory.openSession();
-
-        try {
-            for (Map.Entry<String, Integer> e : nameToId.entrySet())
-                assertEquals((int)e.getValue(), ((Entity)ses.bySimpleNaturalId(Entity.class).load(e.getKey())).getId());
-
-            for (String name : absentNames)
-                assertNull((ses.bySimpleNaturalId(Entity.class).load(name)));
-
-            assertEquals(nameToId.size() + hitBefore, stats.getHitCount());
-
-            assertEquals(absentNames.length + missBefore, stats.getMissCount());
-        }
-        finally {
-            ses.close();
-        }
-    }
-
-    /**
-     * @param sesFactory Session factory.
-     * @param idToChildCnt Number of children per entity.
-     * @param expHit Expected cache hits.
-     * @param expMiss Expected cache misses.
-     */
-    @SuppressWarnings("unchecked")
-    private void assertCollectionCache(SessionFactory sesFactory, Map<Integer, Integer> idToChildCnt, int expHit,
-        int expMiss) {
-        sesFactory.getStatistics().clear();
-
-        Session ses = sesFactory.openSession();
-
-        try {
-            for(Map.Entry<Integer, Integer> e : idToChildCnt.entrySet()) {
-                Entity entity = (Entity)ses.load(Entity.class, e.getKey());
-
-                assertEquals((int)e.getValue(), entity.getChildren().size());
-            }
-        }
-        finally {
-            ses.close();
-        }
-
-        SecondLevelCacheStatistics stats =
-            sesFactory.getStatistics().getSecondLevelCacheStatistics(CHILD_COLLECTION_REGION);
-
-        assertEquals(expHit, stats.getHitCount());
-
-        assertEquals(expMiss, stats.getMissCount());
-    }
-
-    /**
-     * @param sesFactory Session factory.
-     * @param cnt Number of entities to load.
-     */
-    private void loadEntities(SessionFactory sesFactory, int cnt) {
-        Session ses = sesFactory.openSession();
-
-        try {
-            for (int i = 0; i < cnt; i++) {
-                Entity e = (Entity)ses.load(Entity.class, i);
-
-                assertEquals("name-" + i, e.getName());
-
-                assertFalse(e.getChildren().isEmpty());
-
-                ses.bySimpleNaturalId(Entity.class).load(e.getName());
-            }
-        }
-        finally {
-            ses.close();
-        }
-    }
-
-    /**
-     * @param entityName Entity name.
-     * @param sesFactory Session factory.
-     * @param idToName ID to name mapping.
-     * @param absentIds Absent entities' IDs.
-     */
-    private void assertEntityCache(String entityName, SessionFactory sesFactory, Map<Integer, String> idToName,
-        Integer... absentIds) {
-        assert entityName.equals(ENTITY_NAME) || entityName.equals(ENTITY2_NAME) : entityName;
-
-        sesFactory.getStatistics().clear();
-
-        final Session ses = sesFactory.openSession();
-
-        final boolean entity1 = entityName.equals(ENTITY_NAME);
-
-        try {
-            if (entity1) {
-                for (Map.Entry<Integer, String> e : idToName.entrySet())
-                    assertEquals(e.getValue(), ((Entity)ses.load(Entity.class, e.getKey())).getName());
-            }
-            else {
-                for (Map.Entry<Integer, String> e : idToName.entrySet())
-                    assertEquals(e.getValue(), ((Entity2)ses.load(Entity2.class, e.getKey())).getName());
-            }
-
-            for (final int id : absentIds) {
-                GridTestUtils.assertThrows(log, new Callable<Void>() {
-                    @Override public Void call() throws Exception {
-                        if (entity1)
-                            ((Entity)ses.load(Entity.class, id)).getName();
-                        else
-                            ((Entity2)ses.load(Entity2.class, id)).getName();
-
-                        return null;
-                    }
-                }, ObjectNotFoundException.class, null);
-            }
-
-            SecondLevelCacheStatistics stats = sesFactory.getStatistics().getSecondLevelCacheStatistics(entityName);
-
-            assertEquals(idToName.size(), stats.getHitCount());
-
-            assertEquals(absentIds.length, stats.getMissCount());
-        }
-        finally {
-            ses.close();
-        }
-    }
-
-    /**
-     * Creates session factories.
-     *
-     * @param accessType Cache access type.
-     */
-    private void createSessionFactories(AccessType accessType) {
-        sesFactory1 = startHibernate(accessType, getTestIgniteInstanceName(0));
-
-        sesFactory2 = startHibernate(accessType, getTestIgniteInstanceName(1));
-    }
-
-    /**
-     * Starts Hibernate.
-     *
-     * @param accessType Cache access type.
-     * @param igniteInstanceName Ignite instance name.
-     * @return Session factory.
-     */
-    private SessionFactory startHibernate(org.hibernate.cache.spi.access.AccessType accessType, String igniteInstanceName) {
-        StandardServiceRegistryBuilder builder = registryBuilder();
-
-        builder.applySetting(HBM2DDL_AUTO, "create");
-        builder.applySetting(GENERATE_STATISTICS, "true");
-        builder.applySetting(USE_SECOND_LEVEL_CACHE, "true");
-        builder.applySetting(USE_QUERY_CACHE, "true");
-        builder.applySetting(CACHE_REGION_FACTORY, HibernateRegionFactory.class.getName());
-        builder.applySetting(RELEASE_CONNECTIONS, "on_close");
-        builder.applySetting(IGNITE_INSTANCE_NAME_PROPERTY, igniteInstanceName);
-        // Use the same cache for Entity and Entity2.
-        builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, ENTITY_NAME);
-        builder.applySetting(DFLT_ACCESS_TYPE_PROPERTY, accessType.name());
-        builder.applySetting(Environment.DIALECT, "org.hibernate.dialect.H2Dialect");
-        builder.applySetting("hibernate.show_sql", false);
-
-        StandardServiceRegistry srvcRegistry = builder.build();
-
-        MetadataSources metadataSources = new MetadataSources(srvcRegistry);
-
-        for (Class entityClass : getAnnotatedClasses())
-            metadataSources.addAnnotatedClass(entityClass);
-
-        Metadata metadata = metadataSources.buildMetadata();
-
-        for (PersistentClass entityBinding : metadata.getEntityBindings()) {
-            if (!entityBinding.isInherited())
-                ((RootClass)entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
-        }
-
-        for (org.hibernate.mapping.Collection collectionBinding : metadata.getCollectionBindings())
-            collectionBinding.setCacheConcurrencyStrategy( accessType.getExternalName() );
-
-        return metadata.buildSessionFactory();
-    }
-
-    /**
-     * @return Entities classes.
-     */
-    private Class[] getAnnotatedClasses() {
-        return new Class[]{Entity.class, Entity2.class, VersionedEntity.class, ChildEntity.class, ParentEntity.class};
-    }
-
-    /**
-     * Closes session factories and clears data from caches.
-     *
-     * @throws Exception If failed.
-     */
-    private void cleanup() throws Exception {
-        if (sesFactory1 != null)
-            sesFactory1.close();
-
-        sesFactory1 = null;
-
-        if (sesFactory2 != null)
-            sesFactory2.close();
-
-        sesFactory2 = null;
-
-        for (IgniteCacheProxy<?, ?> cache : ((IgniteKernal)grid(0)).caches())
-            cache.clear();
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalSelfTest.java b/modules/hibernate5/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalSelfTest.java
deleted file mode 100644
index 5175292..0000000
--- a/modules/hibernate5/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalSelfTest.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import java.util.Collections;
-import javax.cache.configuration.Factory;
-import javax.transaction.Synchronization;
-import javax.transaction.TransactionManager;
-import javax.transaction.UserTransaction;
-import org.apache.commons.dbcp.managed.BasicManagedDataSource;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.h2.jdbcx.JdbcDataSource;
-import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cfg.Environment;
-import org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl;
-import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
-import org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform;
-import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
-import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl;
-import org.jetbrains.annotations.Nullable;
-import org.objectweb.jotm.Jotm;
-
-/**
- *
- * Tests Hibernate L2 cache with TRANSACTIONAL access mode (Hibernate and Cache are configured
- * to used the same TransactionManager).
- */
-public class HibernateL2CacheTransactionalSelfTest extends HibernateL2CacheSelfTest {
-    /** */
-    private static Jotm jotm;
-
-    /**
-     */
-    private static class TestJtaPlatform extends AbstractJtaPlatform {
-        /** {@inheritDoc} */
-        @Override protected TransactionManager locateTransactionManager() {
-            return jotm.getTransactionManager();
-        }
-
-        /** {@inheritDoc} */
-        @Override protected UserTransaction locateUserTransaction() {
-            return jotm.getUserTransaction();
-        }
-    }
-
-    /**
-     */
-    @SuppressWarnings("PublicInnerClass")
-    public static class TestTmFactory implements Factory<TransactionManager> {
-        /** */
-        private static final long serialVersionUID = 0;
-
-        /** {@inheritDoc} */
-        @Override public TransactionManager create() {
-            return jotm.getTransactionManager();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        jotm = new Jotm(true, false);
-
-        super.beforeTestsStarted();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        super.afterTestsStopped();
-
-        if (jotm != null)
-            jotm.stop();
-
-        jotm = null;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
-
-        cfg.getTransactionConfiguration().setTxManagerFactory(new TestTmFactory());
-        cfg.getTransactionConfiguration().setUseJtaSynchronization(useJtaSynchronization());
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheConfiguration transactionalRegionConfiguration(String regionName) {
-        CacheConfiguration cfg = super.transactionalRegionConfiguration(regionName);
-
-        cfg.setNearConfiguration(null);
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override protected StandardServiceRegistryBuilder registryBuilder() {
-        StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
-
-        DatasourceConnectionProviderImpl connProvider = new DatasourceConnectionProviderImpl();
-
-        BasicManagedDataSource dataSrc = new BasicManagedDataSource(); // JTA-aware data source.
-
-        dataSrc.setTransactionManager(jotm.getTransactionManager());
-
-        dataSrc.setDefaultAutoCommit(false);
-
-        JdbcDataSource h2DataSrc = new JdbcDataSource();
-
-        h2DataSrc.setURL(CONNECTION_URL);
-
-        dataSrc.setXaDataSourceInstance(h2DataSrc);
-
-        connProvider.setDataSource(dataSrc);
-
-        connProvider.configure(Collections.emptyMap());
-
-        builder.addService(ConnectionProvider.class, connProvider);
-
-        builder.addService(JtaPlatform.class, new TestJtaPlatform());
-
-        builder.applySetting(Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName());
-
-        return builder;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected AccessType[] accessTypes() {
-        return new AccessType[]{AccessType.TRANSACTIONAL};
-    }
-
-    /**
-     * @return Whether to use {@link Synchronization}.
-     */
-    protected boolean useJtaSynchronization() {
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalUseSyncSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalUseSyncSelfTest.java b/modules/hibernate5/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalUseSyncSelfTest.java
deleted file mode 100644
index 44899f9..0000000
--- a/modules/hibernate5/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalUseSyncSelfTest.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import javax.transaction.Synchronization;
-
-/**
- * Tests Hibernate L2 cache with TRANSACTIONAL access mode and {@link Synchronization}
- * instead of XA resource.
- */
-public class HibernateL2CacheTransactionalUseSyncSelfTest extends HibernateL2CacheTransactionalSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean useJtaSynchronization() {
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreNodeRestartTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreNodeRestartTest.java b/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreNodeRestartTest.java
deleted file mode 100644
index d5496af..0000000
--- a/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreNodeRestartTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.store.hibernate;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.cache.store.CacheStore;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.integration.IgniteCacheStoreNodeRestartAbstractTest;
-
-public class CacheHibernateBlobStoreNodeRestartTest extends IgniteCacheStoreNodeRestartAbstractTest {
-    /** {@inheritDoc} */
-    @Override protected CacheStore getStore() {
-        return new CacheHibernateBlobStore();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheMode cacheMode() {
-        return CacheMode.PARTITIONED;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheAtomicityMode atomicityMode() {
-        return CacheAtomicityMode.ATOMIC;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected NearCacheConfiguration nearConfiguration() {
-        return null;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreSelfTest.java b/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreSelfTest.java
deleted file mode 100644
index d3d2b52..0000000
--- a/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreSelfTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.store.hibernate;
-
-import java.io.File;
-import java.net.URL;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.testframework.junits.cache.GridAbstractCacheStoreSelfTest;
-import org.hibernate.FlushMode;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-
-/**
- * Cache store test.
- */
-public class CacheHibernateBlobStoreSelfTest extends
-    GridAbstractCacheStoreSelfTest<CacheHibernateBlobStore<Object, Object>> {
-    /**
-     * @throws Exception If failed.
-     */
-    public CacheHibernateBlobStoreSelfTest() throws Exception {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        super.afterTest();
-
-        Session s = store.session(null);
-
-        if (s == null)
-            return;
-
-        try {
-            s.createQuery("delete from " + CacheHibernateBlobStoreEntry.class.getSimpleName())
-                    .setFlushMode(FlushMode.ALWAYS).executeUpdate();
-
-            Transaction hTx = s.getTransaction();
-
-            if (hTx != null && hTx.isActive())
-                hTx.commit();
-        }
-        finally {
-            s.close();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheHibernateBlobStore<Object, Object> store() {
-        return new CacheHibernateBlobStore<>();
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testConfigurationByUrl() throws Exception {
-        URL url = U.resolveIgniteUrl(
-                "modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml");
-
-        assert url != null;
-
-        store.setHibernateConfigurationPath(url.toString());
-
-        // Store will be implicitly initialized.
-        store.load("key");
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testConfigurationByFile() throws Exception {
-        URL url = U.resolveIgniteUrl(
-                "modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml");
-
-        assert url != null;
-
-        File file = new File(url.toURI());
-
-        store.setHibernateConfigurationPath(file.getAbsolutePath());
-
-        // Store will be implicitly initialized.
-        store.load("key");
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testConfigurationByResource() throws Exception {
-        store.setHibernateConfigurationPath("/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml");
-
-        // Store will be implicitly initialized.
-        store.load("key");
-    }
-
-    @Override public void testSimpleMultithreading() throws Exception {
-        fail("https://issues.apache.org/jira/browse/IGNITE-1757");
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreFactorySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreFactorySelfTest.java b/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreFactorySelfTest.java
deleted file mode 100644
index d158f81..0000000
--- a/modules/hibernate5/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreFactorySelfTest.java
+++ /dev/null
@@ -1,326 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.store.hibernate;
-
-import java.sql.Connection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import javax.naming.NamingException;
-import javax.naming.Reference;
-import javax.persistence.EntityGraph;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceUnitUtil;
-import javax.persistence.Query;
-import javax.persistence.SynchronizationType;
-import javax.persistence.criteria.CriteriaBuilder;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.hibernate.Cache;
-import org.hibernate.HibernateException;
-import org.hibernate.Metamodel;
-import org.hibernate.Session;
-import org.hibernate.SessionBuilder;
-import org.hibernate.SessionFactory;
-import org.hibernate.StatelessSession;
-import org.hibernate.StatelessSessionBuilder;
-import org.hibernate.TypeHelper;
-import org.hibernate.boot.spi.SessionFactoryOptions;
-import org.hibernate.engine.spi.FilterDefinition;
-import org.hibernate.metadata.ClassMetadata;
-import org.hibernate.metadata.CollectionMetadata;
-import org.hibernate.stat.Statistics;
-
-/**
- * Test for Cache jdbc blob store factory.
- */
-public class CacheHibernateStoreFactorySelfTest extends GridCommonAbstractTest {
-    /** Cache name. */
-    private static final String CACHE_NAME = "test";
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testCacheConfiguration() throws Exception {
-        try (Ignite ignite1 = startGrid(0)) {
-            IgniteCache<Integer, String> cache1 = ignite1.getOrCreateCache(cacheConfiguration());
-
-            checkStore(cache1);
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testXmlConfiguration() throws Exception {
-        try (Ignite ignite = Ignition.start("modules/hibernate/src/test/config/factory-cache.xml")) {
-            try(Ignite ignite1 = Ignition.start("modules/hibernate/src/test/config/factory-cache1.xml")) {
-                checkStore(ignite.<Integer, String>cache(CACHE_NAME), DummySessionFactoryExt.class);
-
-                checkStore(ignite1.<Integer, String>cache(CACHE_NAME), DummySessionFactory.class);
-            }
-        }
-    }
-
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testIncorrectBeanConfiguration() throws Exception {
-        GridTestUtils.assertThrows(log, new Callable<Object>() {
-            @Override public Object call() throws Exception {
-                try(Ignite ignite =
-                    Ignition.start("modules/hibernate/src/test/config/factory-incorrect-store-cache.xml")) {
-                    ignite.cache(CACHE_NAME).getConfiguration(CacheConfiguration.class).
-                            getCacheStoreFactory().create();
-                }
-                return null;
-            }
-        }, IgniteException.class, "Failed to load bean in application context");
-    }
-
-    /**
-     * @return Cache configuration with store.
-     */
-    private CacheConfiguration<Integer, String> cacheConfiguration() {
-        CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>();
-
-        CacheHibernateBlobStoreFactory<Integer, String> factory = new CacheHibernateBlobStoreFactory();
-
-        factory.setHibernateConfigurationPath("/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml");
-
-        cfg.setCacheStoreFactory(factory);
-
-        return cfg;
-    }
-
-    /**
-     * @param cache Ignite cache.
-     * @param dataSrcClass Data source class.
-     * @throws Exception If store parameters is not the same as in configuration xml.
-     */
-    private void checkStore(IgniteCache<Integer, String> cache, Class<?> dataSrcClass) throws Exception {
-        CacheHibernateBlobStore store = (CacheHibernateBlobStore)cache
-            .getConfiguration(CacheConfiguration.class).getCacheStoreFactory().create();
-
-        assertEquals(dataSrcClass,
-            GridTestUtils.getFieldValue(store, CacheHibernateBlobStore.class, "sesFactory").getClass());
-    }
-
-    /**
-     * @param cache Ignite cache.
-     * @throws Exception If store parameters is not the same as in configuration xml.
-     */
-    private void checkStore(IgniteCache<Integer, String> cache) throws Exception {
-        CacheHibernateBlobStore store = (CacheHibernateBlobStore)cache.getConfiguration(CacheConfiguration.class)
-            .getCacheStoreFactory().create();
-
-        assertEquals("/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml",
-            GridTestUtils.getFieldValue(store, CacheHibernateBlobStore.class, "hibernateCfgPath"));
-    }
-
-    /**
-     *
-     */
-    public static class DummySessionFactoryExt extends DummySessionFactory {
-        /** */
-        public DummySessionFactoryExt() {
-            // No-op.
-        }
-    }
-
-    /**
-     *
-     */
-    public static class DummySessionFactory implements SessionFactory {
-        /** {@inheritDoc} */
-        @Override public SessionFactoryOptions getSessionFactoryOptions() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public SessionBuilder withOptions() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Session openSession() throws HibernateException {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Session getCurrentSession() throws HibernateException {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public StatelessSessionBuilder withStatelessOptions() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public StatelessSession openStatelessSession() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public StatelessSession openStatelessSession(Connection conn) {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public ClassMetadata getClassMetadata(Class entityCls) {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public ClassMetadata getClassMetadata(String entityName) {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public CollectionMetadata getCollectionMetadata(String roleName) {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Map<String, ClassMetadata> getAllClassMetadata() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Map getAllCollectionMetadata() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Statistics getStatistics() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void close() throws HibernateException {
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean isClosed() {
-            return false;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Cache getCache() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Set getDefinedFilterNames() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public FilterDefinition getFilterDefinition(String filterName) throws HibernateException {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean containsFetchProfileDefinition(String name) {
-            return false;
-        }
-
-        /** {@inheritDoc} */
-        @Override public TypeHelper getTypeHelper() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Reference getReference() throws NamingException {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public EntityManager createEntityManager() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public EntityManager createEntityManager(Map map) {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public EntityManager createEntityManager(SynchronizationType synchronizationType) {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public EntityManager createEntityManager(SynchronizationType synchronizationType, Map map) {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public CriteriaBuilder getCriteriaBuilder() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean isOpen() {
-            return false;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Map<String, Object> getProperties() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public PersistenceUnitUtil getPersistenceUnitUtil() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void addNamedQuery(String s, Query qry) {
-            // No-op.
-        }
-
-        /** {@inheritDoc} */
-        @Override public <T> T unwrap(Class<T> aCls) {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public <T> void addNamedEntityGraph(String s, EntityGraph<T> entityGraph) {
-            // No-op.
-        }
-
-        /** {@inheritDoc} */
-        @Override public <T> List<EntityGraph<? super T>> findEntityGraphsByType(Class<T> entityCls) {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Metamodel getMetamodel() {
-            return null;
-        }
-    }
-}
\ No newline at end of file


[05/16] ignite git commit: ignite-1794 Refactored hibernate modules, switched to hibernate 5.1

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListenerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListenerSelfTest.java b/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListenerSelfTest.java
deleted file mode 100644
index 880d12a..0000000
--- a/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListenerSelfTest.java
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.store.hibernate;
-
-import java.io.Serializable;
-import java.util.Map;
-import javax.cache.Cache;
-import javax.cache.configuration.Factory;
-import javax.cache.integration.CacheLoaderException;
-import javax.cache.integration.CacheWriterException;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.Table;
-import org.apache.ignite.cache.store.CacheStore;
-import org.apache.ignite.cache.store.CacheStoreAdapter;
-import org.apache.ignite.cache.store.CacheStoreSession;
-import org.apache.ignite.cache.store.CacheStoreSessionListener;
-import org.apache.ignite.cache.store.CacheStoreSessionListenerAbstractSelfTest;
-import org.apache.ignite.cache.store.jdbc.CacheJdbcStoreSessionListener;
-import org.apache.ignite.lang.IgniteBiInClosure;
-import org.apache.ignite.resources.CacheStoreSessionResource;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.Transaction;
-import org.hibernate.cfg.Configuration;
-
-/**
- * Tests for {@link CacheJdbcStoreSessionListener}.
- */
-public class CacheHibernateStoreSessionListenerSelfTest extends CacheStoreSessionListenerAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override protected Factory<? extends CacheStore<Integer, Integer>> storeFactory() {
-        return new Factory<CacheStore<Integer, Integer>>() {
-            @Override public CacheStore<Integer, Integer> create() {
-                return new Store();
-            }
-        };
-    }
-
-    /** {@inheritDoc} */
-    @Override protected Factory<CacheStoreSessionListener> sessionListenerFactory() {
-        return new Factory<CacheStoreSessionListener>() {
-            @Override public CacheStoreSessionListener create() {
-                CacheHibernateStoreSessionListener lsnr = new CacheHibernateStoreSessionListener();
-
-                SessionFactory sesFactory = new Configuration().
-                    setProperty("hibernate.connection.url", URL).
-                    addAnnotatedClass(Table1.class).
-                    addAnnotatedClass(Table2.class).
-                    buildSessionFactory();
-
-                lsnr.setSessionFactory(sesFactory);
-
-                return lsnr;
-            }
-        };
-    }
-
-    /**
-     */
-    private static class Store extends CacheStoreAdapter<Integer, Integer> {
-        /** */
-        private static String SES_CONN_KEY = "ses_conn";
-
-        /** */
-        @CacheStoreSessionResource
-        private CacheStoreSession ses;
-
-        /** {@inheritDoc} */
-        @Override public void loadCache(IgniteBiInClosure<Integer, Integer> clo, Object... args) {
-            loadCacheCnt.incrementAndGet();
-
-            checkSession();
-        }
-
-        /** {@inheritDoc} */
-        @Override public Integer load(Integer key) throws CacheLoaderException {
-            loadCnt.incrementAndGet();
-
-            checkSession();
-
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void write(Cache.Entry<? extends Integer, ? extends Integer> entry)
-            throws CacheWriterException {
-            writeCnt.incrementAndGet();
-
-            checkSession();
-
-            if (write.get()) {
-                Session hibSes = ses.attachment();
-
-                switch (ses.cacheName()) {
-                    case "cache1":
-                        hibSes.save(new Table1(entry.getKey(), entry.getValue()));
-
-                        break;
-
-                    case "cache2":
-                        if (fail.get())
-                            throw new CacheWriterException("Expected failure.");
-
-                        hibSes.save(new Table2(entry.getKey(), entry.getValue()));
-
-                        break;
-
-                    default:
-                        throw new CacheWriterException("Wring cache: " + ses.cacheName());
-                }
-            }
-        }
-
-        /** {@inheritDoc} */
-        @Override public void delete(Object key) throws CacheWriterException {
-            deleteCnt.incrementAndGet();
-
-            checkSession();
-        }
-
-        /** {@inheritDoc} */
-        @Override public void sessionEnd(boolean commit) {
-            assertNull(ses.attachment());
-        }
-
-        /**
-         */
-        private void checkSession() {
-            Session hibSes = ses.attachment();
-
-            assertNotNull(hibSes);
-
-            assertTrue(hibSes.isOpen());
-
-            Transaction tx = hibSes.getTransaction();
-
-            assertNotNull(tx);
-
-            if (ses.isWithinTransaction())
-                assertTrue(tx.isActive());
-            else
-                assertFalse(tx.isActive());
-
-            verifySameInstance(hibSes);
-        }
-
-        /**
-         * @param hibSes Session.
-         */
-        private void verifySameInstance(Session hibSes) {
-            Map<String, Session> props = ses.properties();
-
-            Session sesConn = props.get(SES_CONN_KEY);
-
-            if (sesConn == null)
-                props.put(SES_CONN_KEY, hibSes);
-            else {
-                assertSame(hibSes, sesConn);
-
-                reuseCnt.incrementAndGet();
-            }
-        }
-    }
-
-    /**
-     */
-    @Entity
-    @Table(name = "Table1")
-    private static class Table1 implements Serializable {
-        /** */
-        @Id @GeneratedValue
-        @Column(name = "id")
-        private Integer id;
-
-        /** */
-        @Column(name = "key")
-        private int key;
-
-        /** */
-        @Column(name = "value")
-        private int value;
-
-        /**
-         * @param key Key.
-         * @param value Value.
-         */
-        private Table1(int key, int value) {
-            this.key = key;
-            this.value = value;
-        }
-    }
-
-    /**
-     */
-    @Entity
-    @Table(name = "Table2")
-    private static class Table2 implements Serializable {
-        /** */
-        @Id @GeneratedValue
-        @Column(name = "id")
-        private Integer id;
-
-        /** */
-        @Column(name = "key")
-        private int key;
-
-        /** */
-        @Column(name = "value")
-        private int value;
-
-        /**
-         * @param key Key.
-         * @param value Value.
-         */
-        private Table2(int key, int value) {
-            this.key = key;
-            this.value = value;
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml b/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml
deleted file mode 100644
index 3822b31..0000000
--- a/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml
+++ /dev/null
@@ -1,42 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one or more
-  contributor license agreements.  See the NOTICE file distributed with
-  this work for additional information regarding copyright ownership.
-  The ASF licenses this file to You under the Apache License, Version 2.0
-  (the "License"); you may not use this file except in compliance with
-  the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-
-
-<!DOCTYPE hibernate-configuration PUBLIC
-        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
-        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
-
-<hibernate-configuration>
-    <session-factory>
-        <!-- Show SQL. -->
-        <property name="show_sql">true</property>
-
-        <!-- Database connection settings (private in-memory database). -->
-        <property name="connection.url">jdbc:h2:mem:example;DB_CLOSE_DELAY=-1</property>
-
-        <!-- Only validate the database schema on startup in production mode. -->
-        <property name="hbm2ddl.auto">update</property>
-
-        <!-- H2 dialect. -->
-        <property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
-
-        <!-- Mappings. -->
-        <mapping resource="org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml"/>
-    </session-factory>
-</hibernate-configuration>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/package-info.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/package-info.java b/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/package-info.java
deleted file mode 100644
index 8af9886..0000000
--- a/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * <!-- Package description. -->
- * Contains internal tests or test related classes and interfaces.
- */
-package org.apache.ignite.cache.store.hibernate;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/test/java/org/apache/ignite/testsuites/IgniteBinaryHibernateTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/test/java/org/apache/ignite/testsuites/IgniteBinaryHibernateTestSuite.java b/modules/hibernate/src/test/java/org/apache/ignite/testsuites/IgniteBinaryHibernateTestSuite.java
deleted file mode 100644
index 3791bae..0000000
--- a/modules/hibernate/src/test/java/org/apache/ignite/testsuites/IgniteBinaryHibernateTestSuite.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.testsuites;
-
-import junit.framework.TestSuite;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
-import org.apache.ignite.testframework.config.GridTestProperties;
-
-/**
- *
- */
-public class IgniteBinaryHibernateTestSuite extends TestSuite {
-    /**
-     * @return Test suite.
-     * @throws Exception If failed.
-     */
-    public static TestSuite suite() throws Exception {
-        GridTestProperties.setProperty(GridTestProperties.MARSH_CLASS_NAME, BinaryMarshaller.class.getName());
-
-        return IgniteHibernateTestSuite.suite();
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/test/java/org/apache/ignite/testsuites/IgniteHibernateTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/test/java/org/apache/ignite/testsuites/IgniteHibernateTestSuite.java b/modules/hibernate/src/test/java/org/apache/ignite/testsuites/IgniteHibernateTestSuite.java
deleted file mode 100644
index 99fea56..0000000
--- a/modules/hibernate/src/test/java/org/apache/ignite/testsuites/IgniteHibernateTestSuite.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.testsuites;
-
-import junit.framework.TestSuite;
-import org.apache.ignite.cache.hibernate.HibernateL2CacheConfigurationSelfTest;
-import org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest;
-import org.apache.ignite.cache.hibernate.HibernateL2CacheTransactionalSelfTest;
-import org.apache.ignite.cache.hibernate.HibernateL2CacheTransactionalUseSyncSelfTest;
-import org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreNodeRestartTest;
-import org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreSelfTest;
-import org.apache.ignite.cache.store.hibernate.CacheHibernateStoreFactorySelfTest;
-import org.apache.ignite.cache.store.hibernate.CacheHibernateStoreSessionListenerSelfTest;
-
-/**
- * Hibernate integration tests.
- */
-public class IgniteHibernateTestSuite extends TestSuite {
-    /**
-     * @return Test suite.
-     * @throws Exception Thrown in case of the failure.
-     */
-    public static TestSuite suite() throws Exception {
-        TestSuite suite = new TestSuite("Hibernate Integration Test Suite");
-
-        // Hibernate L2 cache.
-        suite.addTestSuite(HibernateL2CacheSelfTest.class);
-        suite.addTestSuite(HibernateL2CacheTransactionalSelfTest.class);
-        suite.addTestSuite(HibernateL2CacheTransactionalUseSyncSelfTest.class);
-        suite.addTestSuite(HibernateL2CacheConfigurationSelfTest.class);
-
-        suite.addTestSuite(CacheHibernateBlobStoreSelfTest.class);
-
-        suite.addTestSuite(CacheHibernateBlobStoreNodeRestartTest.class);
-
-        suite.addTestSuite(CacheHibernateStoreSessionListenerSelfTest.class);
-
-        suite.addTestSuite(CacheHibernateStoreFactorySelfTest.class);
-
-        return suite;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/README.txt
----------------------------------------------------------------------
diff --git a/modules/hibernate5/README.txt b/modules/hibernate5/README.txt
deleted file mode 100644
index 370258b..0000000
--- a/modules/hibernate5/README.txt
+++ /dev/null
@@ -1,48 +0,0 @@
-Apache Ignite Hibernate Module
-------------------------------
-
-Apache Ignite Hibernate module provides Hibernate second-level cache (L2 cache) implementation based
-on Apache Ignite In-Memory Data Grid.
-
-To enable Hibernate module when starting a standalone node, move 'optional/ignite-hibernate5' folder to
-'libs' folder before running 'ignite.{sh|bat}' script. The content of the module folder will
-be added to classpath in this case.
-
-Importing Hibernate Module In Maven Project
--------------------------------------------
-
-If you are using Maven to manage dependencies of your project, you can add Hibernate module
-dependency like this (replace '${ignite.version}' with actual Ignite version you are
-interested in):
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
-                        http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    ...
-    <dependencies>
-        ...
-        <dependency>
-            <groupId>org.apache.ignite</groupId>
-            <artifactId>ignite-hibernate5</artifactId>
-            <version>${ignite.version}</version>
-        </dependency>
-        ...
-    </dependencies>
-    ...
-</project>
-
-
-LGPL dependencies
------------------
-
-Ignite includes the following optional LGPL dependencies:
- - Hibernate L2 Cache Integration, http://hibernate.org/orm/
- - JTS Topology Suite for Geospatial indexing, http://tsusiatsoftware.net/jts/main.html
- - cron4j for cron-based task scheduling, http://www.sauronsoftware.it/projects/cron4j
-
-Apache binary releases cannot include LGPL dependencies. If you would like include
-optional LGPL dependencies into your release, you should download the source release
-from Ignite website and do the build with the following maven command:
-
-mvn clean package -DskipTests -Prelease,lgpl

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/licenses/apache-2.0.txt
----------------------------------------------------------------------
diff --git a/modules/hibernate5/licenses/apache-2.0.txt b/modules/hibernate5/licenses/apache-2.0.txt
deleted file mode 100644
index d645695..0000000
--- a/modules/hibernate5/licenses/apache-2.0.txt
+++ /dev/null
@@ -1,202 +0,0 @@
-
-                                 Apache License
-                           Version 2.0, January 2004
-                        http://www.apache.org/licenses/
-
-   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
-   1. Definitions.
-
-      "License" shall mean the terms and conditions for use, reproduction,
-      and distribution as defined by Sections 1 through 9 of this document.
-
-      "Licensor" shall mean the copyright owner or entity authorized by
-      the copyright owner that is granting the License.
-
-      "Legal Entity" shall mean the union of the acting entity and all
-      other entities that control, are controlled by, or are under common
-      control with that entity. For the purposes of this definition,
-      "control" means (i) the power, direct or indirect, to cause the
-      direction or management of such entity, whether by contract or
-      otherwise, or (ii) ownership of fifty percent (50%) or more of the
-      outstanding shares, or (iii) beneficial ownership of such entity.
-
-      "You" (or "Your") shall mean an individual or Legal Entity
-      exercising permissions granted by this License.
-
-      "Source" form shall mean the preferred form for making modifications,
-      including but not limited to software source code, documentation
-      source, and configuration files.
-
-      "Object" form shall mean any form resulting from mechanical
-      transformation or translation of a Source form, including but
-      not limited to compiled object code, generated documentation,
-      and conversions to other media types.
-
-      "Work" shall mean the work of authorship, whether in Source or
-      Object form, made available under the License, as indicated by a
-      copyright notice that is included in or attached to the work
-      (an example is provided in the Appendix below).
-
-      "Derivative Works" shall mean any work, whether in Source or Object
-      form, that is based on (or derived from) the Work and for which the
-      editorial revisions, annotations, elaborations, or other modifications
-      represent, as a whole, an original work of authorship. For the purposes
-      of this License, Derivative Works shall not include works that remain
-      separable from, or merely link (or bind by name) to the interfaces of,
-      the Work and Derivative Works thereof.
-
-      "Contribution" shall mean any work of authorship, including
-      the original version of the Work and any modifications or additions
-      to that Work or Derivative Works thereof, that is intentionally
-      submitted to Licensor for inclusion in the Work by the copyright owner
-      or by an individual or Legal Entity authorized to submit on behalf of
-      the copyright owner. For the purposes of this definition, "submitted"
-      means any form of electronic, verbal, or written communication sent
-      to the Licensor or its representatives, including but not limited to
-      communication on electronic mailing lists, source code control systems,
-      and issue tracking systems that are managed by, or on behalf of, the
-      Licensor for the purpose of discussing and improving the Work, but
-      excluding communication that is conspicuously marked or otherwise
-      designated in writing by the copyright owner as "Not a Contribution."
-
-      "Contributor" shall mean Licensor and any individual or Legal Entity
-      on behalf of whom a Contribution has been received by Licensor and
-      subsequently incorporated within the Work.
-
-   2. Grant of Copyright License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      copyright license to reproduce, prepare Derivative Works of,
-      publicly display, publicly perform, sublicense, and distribute the
-      Work and such Derivative Works in Source or Object form.
-
-   3. Grant of Patent License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      (except as stated in this section) patent license to make, have made,
-      use, offer to sell, sell, import, and otherwise transfer the Work,
-      where such license applies only to those patent claims licensable
-      by such Contributor that are necessarily infringed by their
-      Contribution(s) alone or by combination of their Contribution(s)
-      with the Work to which such Contribution(s) was submitted. If You
-      institute patent litigation against any entity (including a
-      cross-claim or counterclaim in a lawsuit) alleging that the Work
-      or a Contribution incorporated within the Work constitutes direct
-      or contributory patent infringement, then any patent licenses
-      granted to You under this License for that Work shall terminate
-      as of the date such litigation is filed.
-
-   4. Redistribution. You may reproduce and distribute copies of the
-      Work or Derivative Works thereof in any medium, with or without
-      modifications, and in Source or Object form, provided that You
-      meet the following conditions:
-
-      (a) You must give any other recipients of the Work or
-          Derivative Works a copy of this License; and
-
-      (b) You must cause any modified files to carry prominent notices
-          stating that You changed the files; and
-
-      (c) You must retain, in the Source form of any Derivative Works
-          that You distribute, all copyright, patent, trademark, and
-          attribution notices from the Source form of the Work,
-          excluding those notices that do not pertain to any part of
-          the Derivative Works; and
-
-      (d) If the Work includes a "NOTICE" text file as part of its
-          distribution, then any Derivative Works that You distribute must
-          include a readable copy of the attribution notices contained
-          within such NOTICE file, excluding those notices that do not
-          pertain to any part of the Derivative Works, in at least one
-          of the following places: within a NOTICE text file distributed
-          as part of the Derivative Works; within the Source form or
-          documentation, if provided along with the Derivative Works; or,
-          within a display generated by the Derivative Works, if and
-          wherever such third-party notices normally appear. The contents
-          of the NOTICE file are for informational purposes only and
-          do not modify the License. You may add Your own attribution
-          notices within Derivative Works that You distribute, alongside
-          or as an addendum to the NOTICE text from the Work, provided
-          that such additional attribution notices cannot be construed
-          as modifying the License.
-
-      You may add Your own copyright statement to Your modifications and
-      may provide additional or different license terms and conditions
-      for use, reproduction, or distribution of Your modifications, or
-      for any such Derivative Works as a whole, provided Your use,
-      reproduction, and distribution of the Work otherwise complies with
-      the conditions stated in this License.
-
-   5. Submission of Contributions. Unless You explicitly state otherwise,
-      any Contribution intentionally submitted for inclusion in the Work
-      by You to the Licensor shall be under the terms and conditions of
-      this License, without any additional terms or conditions.
-      Notwithstanding the above, nothing herein shall supersede or modify
-      the terms of any separate license agreement you may have executed
-      with Licensor regarding such Contributions.
-
-   6. Trademarks. This License does not grant permission to use the trade
-      names, trademarks, service marks, or product names of the Licensor,
-      except as required for reasonable and customary use in describing the
-      origin of the Work and reproducing the content of the NOTICE file.
-
-   7. Disclaimer of Warranty. Unless required by applicable law or
-      agreed to in writing, Licensor provides the Work (and each
-      Contributor provides its Contributions) on an "AS IS" BASIS,
-      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-      implied, including, without limitation, any warranties or conditions
-      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
-      PARTICULAR PURPOSE. You are solely responsible for determining the
-      appropriateness of using or redistributing the Work and assume any
-      risks associated with Your exercise of permissions under this License.
-
-   8. Limitation of Liability. In no event and under no legal theory,
-      whether in tort (including negligence), contract, or otherwise,
-      unless required by applicable law (such as deliberate and grossly
-      negligent acts) or agreed to in writing, shall any Contributor be
-      liable to You for damages, including any direct, indirect, special,
-      incidental, or consequential damages of any character arising as a
-      result of this License or out of the use or inability to use the
-      Work (including but not limited to damages for loss of goodwill,
-      work stoppage, computer failure or malfunction, or any and all
-      other commercial damages or losses), even if such Contributor
-      has been advised of the possibility of such damages.
-
-   9. Accepting Warranty or Additional Liability. While redistributing
-      the Work or Derivative Works thereof, You may choose to offer,
-      and charge a fee for, acceptance of support, warranty, indemnity,
-      or other liability obligations and/or rights consistent with this
-      License. However, in accepting such obligations, You may act only
-      on Your own behalf and on Your sole responsibility, not on behalf
-      of any other Contributor, and only if You agree to indemnify,
-      defend, and hold each Contributor harmless for any liability
-      incurred by, or claims asserted against, such Contributor by reason
-      of your accepting any such warranty or additional liability.
-
-   END OF TERMS AND CONDITIONS
-
-   APPENDIX: How to apply the Apache License to your work.
-
-      To apply the Apache License to your work, attach the following
-      boilerplate notice, with the fields enclosed by brackets "[]"
-      replaced with your own identifying information. (Don't include
-      the brackets!)  The text should be enclosed in the appropriate
-      comment syntax for the file format. We also recommend that a
-      file or class name and description of purpose be included on the
-      same "printed page" as the copyright notice for easier
-      identification within third-party archives.
-
-   Copyright [yyyy] [name of copyright owner]
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/pom.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate5/pom.xml b/modules/hibernate5/pom.xml
deleted file mode 100644
index 13a0c40..0000000
--- a/modules/hibernate5/pom.xml
+++ /dev/null
@@ -1,146 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one or more
-  contributor license agreements.  See the NOTICE file distributed with
-  this work for additional information regarding copyright ownership.
-  The ASF licenses this file to You under the Apache License, Version 2.0
-  (the "License"); you may not use this file except in compliance with
-  the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-
-<!--
-    POM file.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-
-    <parent>
-        <groupId>org.apache.ignite</groupId>
-        <artifactId>ignite-parent</artifactId>
-        <version>1</version>
-        <relativePath>../../parent</relativePath>
-    </parent>
-
-    <artifactId>ignite-hibernate5</artifactId>
-    <version>2.0.0-SNAPSHOT</version>
-    <url>http://ignite.apache.org</url>
-
-    <dependencies>
-        <dependency>
-            <groupId>org.apache.ignite</groupId>
-            <artifactId>ignite-core</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.hibernate</groupId>
-            <artifactId>hibernate-core</artifactId>
-            <version>5.2.9.Final</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.ignite</groupId>
-            <artifactId>ignite-jta</artifactId>
-            <version>${project.version}</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.ow2.jotm</groupId>
-            <artifactId>jotm-core</artifactId>
-            <version>2.1.9</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>commons-dbcp</groupId>
-            <artifactId>commons-dbcp</artifactId>
-            <version>1.4</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>com.h2database</groupId>
-            <artifactId>h2</artifactId>
-            <version>${h2.version}</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>javax.resource</groupId>
-            <artifactId>connector-api</artifactId>
-            <version>1.5</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.ignite</groupId>
-            <artifactId>ignite-core</artifactId>
-            <version>${project.version}</version>
-            <type>test-jar</type>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.ignite</groupId>
-            <artifactId>ignite-spring</artifactId>
-            <version>${project.version}</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.ignite</groupId>
-            <artifactId>ignite-log4j</artifactId>
-            <version>${project.version}</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.springframework</groupId>
-            <artifactId>spring-beans</artifactId>
-            <version>${spring.version}</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.springframework</groupId>
-            <artifactId>spring-context</artifactId>
-            <version>${spring.version}</version>
-            <scope>test</scope>
-        </dependency>
-    </dependencies>
-
-    <build>
-        <testResources>
-            <testResource>
-                <directory>src/main/java</directory>
-                <excludes>
-                    <exclude>**/*.java</exclude>
-                </excludes>
-            </testResource>
-            <testResource>
-                <directory>src/test/java</directory>
-                <excludes>
-                    <exclude>**/*.java</exclude>
-                </excludes>
-            </testResource>
-        </testResources>
-
-        <plugins>
-            <!-- Generate the OSGi MANIFEST.MF for this bundle. -->
-            <plugin>
-                <groupId>org.apache.felix</groupId>
-                <artifactId>maven-bundle-plugin</artifactId>
-            </plugin>
-        </plugins>
-    </build>
-</project>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateAbstractRegionAccessStrategy.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateAbstractRegionAccessStrategy.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateAbstractRegionAccessStrategy.java
deleted file mode 100644
index efb9056..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateAbstractRegionAccessStrategy.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.access.RegionAccessStrategy;
-import org.hibernate.cache.spi.access.SoftLock;
-import org.hibernate.engine.spi.SharedSessionContractImplementor;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Implementation of L2 cache access strategy delegating to {@link HibernateAccessStrategyAdapter}.
- */
-public abstract class HibernateAbstractRegionAccessStrategy implements RegionAccessStrategy {
-    /** */
-    protected final HibernateAccessStrategyAdapter stgy;
-
-    /**
-     * @param stgy Access strategy implementation.
-     */
-    protected HibernateAbstractRegionAccessStrategy(HibernateAccessStrategyAdapter stgy) {
-        this.stgy = stgy;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object get(SharedSessionContractImplementor ses, Object key, long txTs) throws CacheException {
-        return stgy.get(key);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean putFromLoad(SharedSessionContractImplementor ses, Object key, Object val, long txTs, Object ver) throws CacheException {
-        stgy.putFromLoad(key, val);
-
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean putFromLoad(SharedSessionContractImplementor ses, Object key, Object val, long txTs, Object ver, boolean minimalPutOverride)
-        throws CacheException {
-        stgy.putFromLoad(key, val, minimalPutOverride);
-
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public SoftLock lockItem(SharedSessionContractImplementor ses, Object key, Object ver) throws CacheException {
-        return stgy.lock(key);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public SoftLock lockRegion() throws CacheException {
-        return stgy.lockRegion();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unlockRegion(SoftLock lock) throws CacheException {
-        stgy.unlockRegion(lock);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unlockItem(SharedSessionContractImplementor ses, Object key, SoftLock lock) throws CacheException {
-        stgy.unlock(key, lock);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void remove(SharedSessionContractImplementor ses, Object key) throws CacheException {
-        stgy.remove(key);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void removeAll() throws CacheException {
-        stgy.removeAll();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void evict(Object key) throws CacheException {
-        stgy.evict(key);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void evictAll() throws CacheException {
-        stgy.evictAll();
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyAdapter.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyAdapter.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyAdapter.java
deleted file mode 100644
index f6c1d0e..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyAdapter.java
+++ /dev/null
@@ -1,379 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteCallable;
-import org.apache.ignite.resources.IgniteInstanceResource;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
-import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
-import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy;
-import org.hibernate.cache.spi.access.RegionAccessStrategy;
-import org.hibernate.cache.spi.access.SoftLock;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Common interface used to implement Hibernate L2 cache access strategies ({@link RegionAccessStrategy},
- * {@link EntityRegionAccessStrategy} and {@link CollectionRegionAccessStrategy}).
- * <p>
- * The expected sequences of steps related to various CRUD operations executed by Hibernate are:
- * <p>
- * Insert:
- * <ul>
- *     <li>Start DB transaction.</li>
- *     <li>Execute database insert.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#insert}.</li>
- *     <li>Commit DB transaction.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#afterInsert}.</li>
- * </ul>
- * In case if some step fails and DB transaction is rolled back then
- * {@link HibernateAccessStrategyAdapter#afterInsert} is not called.
- * <p>
- * Update:
- * <ul>
- *     <li>Start DB transaction.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#lock}.</li>
- *     <li>Execute database update.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#update}.</li>
- *     <li>Commit DB transaction.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#afterUpdate}.</li>
- * </ul>
- * In case if {@link HibernateAccessStrategyAdapter#lock} was called, but some other step fails and DB
- * transaction is rolled back then {@link HibernateAccessStrategyAdapter#unlock} is called for all locked keys.
- * <p>
- * Delete:
- * <ul>
- *     <li>Start DB transaction.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#lock} for removing key.</li>
- *     <li>Execute database delete.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#remove}.</li>
- *     <li>Commit DB transaction.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#unlock}.</li>
- * </ul>
- * In case if {@link HibernateAccessStrategyAdapter#lock} was called, but some other step fails and DB
- * transaction is rolled back then {@link HibernateAccessStrategyAdapter#unlock} is called for all locked keys.
- * <p>
- * In case if custom SQL update query is executed Hibernate clears entire cache region,
- * for this case operations sequence is:
- * <ul>
- *     <li>Start DB transaction.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#lockRegion}.</li>
- *     <li>Execute database query.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#removeAll}.</li>
- *     <li>Commit DB transaction.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#unlockRegion}.</li>
- * </ul>
- */
-public abstract class HibernateAccessStrategyAdapter {
-    /** */
-    protected final HibernateCacheProxy cache;
-
-    /** Grid. */
-    protected final Ignite ignite;
-
-    /** */
-    protected final IgniteLogger log;
-
-    /**
-     * @param ignite Grid.
-     * @param cache Cache.
-     */
-    protected HibernateAccessStrategyAdapter(Ignite ignite, HibernateCacheProxy cache) {
-        this.cache = cache;
-        this.ignite = ignite;
-
-        log = ignite.log();
-    }
-
-    /**
-     * Gets value from cache. Used by {@link RegionAccessStrategy#get}.
-     *
-     * @param key Key.
-     * @return Cached value.
-     * @throws CacheException If failed.
-     */
-    @Nullable protected Object get(Object key) throws CacheException {
-        try {
-            return cache.get(key);
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /**
-     * Puts in cache value loaded from the database. Used by {@link RegionAccessStrategy#putFromLoad}.
-     *
-     * @param key Key.
-     * @param val Value.
-     * @param minimalPutOverride MinimalPut flag
-     * @throws CacheException If failed.
-     */
-    protected void putFromLoad(Object key, Object val, boolean minimalPutOverride) throws CacheException {
-        putFromLoad(key, val);
-    }
-
-    /**
-     * Puts in cache value loaded from the database. Used by {@link RegionAccessStrategy#putFromLoad}.
-     *
-     * @param key Key.
-     * @param val Value.
-     * @throws CacheException If failed.
-     */
-    protected void putFromLoad(Object key, Object val) throws CacheException {
-        try {
-            cache.put(key, val);
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /**
-     * Called during database transaction execution before Hibernate attempts to update or remove given key.
-     * Used by {@link RegionAccessStrategy#lockItem}.
-     *
-     * @param key Key.
-     * @return Lock representation or {@code null}.
-     * @throws CacheException If failed.
-     */
-    @Nullable protected abstract SoftLock lock(Object key) throws CacheException;
-
-    /**
-     * Called after Hibernate failed to update or successfully removed given key.
-     * Used by {@link RegionAccessStrategy#unlockItem}.
-     *
-     * @param key Key.
-     * @param lock The lock previously obtained from {@link #lock}
-     * @throws CacheException If failed.
-     */
-    protected abstract void unlock(Object key, SoftLock lock) throws CacheException;
-
-    /**
-     * Called after Hibernate updated object in the database but before transaction completed.
-     * Used by {@link EntityRegionAccessStrategy#update} and {@link NaturalIdRegionAccessStrategy#update}.
-     *
-     * @param key Key.
-     * @param val Value.
-     * @return {@code True} if operation updated cache.
-     * @throws CacheException If failed.
-     */
-    protected abstract boolean update(Object key, Object val) throws CacheException;
-
-    /**
-     * Called after Hibernate updated object in the database and transaction successfully completed.
-     * Used by {@link EntityRegionAccessStrategy#afterUpdate} and {@link NaturalIdRegionAccessStrategy#afterUpdate}.
-     *
-     * @param key Key.
-     * @param val Value.
-     * @param lock The lock previously obtained from {@link #lock}
-     * @return {@code True} if operation updated cache.
-     * @throws CacheException If failed.
-     */
-    protected abstract boolean afterUpdate(Object key, Object val, SoftLock lock) throws CacheException;
-
-    /**
-     * Called after Hibernate inserted object in the database but before transaction completed.
-     * Used by {@link EntityRegionAccessStrategy#insert} and {@link NaturalIdRegionAccessStrategy#insert}.
-     *
-     * @param key Key.
-     * @param val Value.
-     * @return {@code True} if operation updated cache.
-     * @throws CacheException If failed.
-     */
-    protected abstract boolean insert(Object key, Object val) throws CacheException;
-
-    /**
-     * Called after Hibernate inserted object in the database and transaction successfully completed.
-     * Used by {@link EntityRegionAccessStrategy#afterInsert} and {@link NaturalIdRegionAccessStrategy#afterInsert}.
-     *
-     * @param key Key.
-     * @param val Value.
-     * @return {@code True} if operation updated cache.
-     * @throws CacheException If failed.
-     */
-    protected abstract boolean afterInsert(Object key, Object val) throws CacheException;
-
-    /**
-     * Called after Hibernate removed object from database but before transaction completed.
-     * Used by {@link RegionAccessStrategy#remove}.
-     *
-     * @param key Key,
-     * @throws CacheException If failed.
-     */
-    protected abstract void remove(Object key) throws CacheException;
-
-    /**
-     * Called to remove object from cache without regard to transaction.
-     * Used by {@link RegionAccessStrategy#evict}.
-     *
-     * @param key Key.
-     * @throws CacheException If failed.
-     */
-    protected void evict(Object key) throws CacheException {
-        evict(ignite, cache, key);
-    }
-
-    /**
-     * Called to remove all data from cache without regard to transaction.
-     * Used by {@link RegionAccessStrategy#evictAll}.
-     *
-     * @throws CacheException If failed.
-     */
-    protected void evictAll() throws CacheException {
-        evictAll(cache);
-    }
-
-    /**
-     * Called during database transaction execution before Hibernate executed
-     * update operation which should invalidate entire cache region.
-     * Used by {@link RegionAccessStrategy#lockRegion}.
-     *
-     * @throws CacheException If failed.
-     * @return Lock representation or {@code null}.
-     */
-    @Nullable protected SoftLock lockRegion() throws CacheException {
-        return null;
-    }
-
-    /**
-     * Called after transaction clearing entire cache region completed.
-     * Used by {@link RegionAccessStrategy#unlockRegion}.
-     *
-     * @param lock The lock previously obtained from {@link #lockRegion}
-     * @throws CacheException If failed.
-     */
-    protected void unlockRegion(SoftLock lock) throws CacheException {
-        // No-op.
-    }
-
-    /**
-     * Called during database transaction execution to clear entire cache region after
-     * Hibernate executed database update, but before transaction completed.
-     * Used by {@link RegionAccessStrategy#removeAll}.
-     *
-     * @throws CacheException If failed.
-     */
-    protected final void removeAll() throws CacheException {
-        evictAll();
-    }
-
-    /**
-     * Called to remove object from cache without regard to transaction.
-     *
-     * @param ignite Grid.
-     * @param cache Cache.
-     * @param key Key.
-     * @throws CacheException If failed.
-     */
-    static void evict(Ignite ignite, HibernateCacheProxy cache, Object key) throws CacheException {
-        try {
-            key = cache.keyTransformer().transform(key);
-
-            ignite.compute(ignite.cluster()).call(new ClearKeyCallable(key, cache.name()));
-        }
-        catch (IgniteException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /**
-     * Called to remove all data from cache without regard to transaction.
-     *
-     * @param cache Cache.
-     * @throws CacheException If failed.
-     */
-    static void evictAll(IgniteInternalCache<Object,Object> cache) throws CacheException {
-        try {
-            cache.clear();
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /**
-     * Callable invalidates given key.
-     */
-    private static class ClearKeyCallable implements IgniteCallable<Void>, Externalizable {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /** */
-        @IgniteInstanceResource
-        private Ignite ignite;
-
-        /** */
-        private Object key;
-
-        /** */
-        private String cacheName;
-
-        /**
-         * Empty constructor required by {@link Externalizable}.
-         */
-        public ClearKeyCallable() {
-            // No-op.
-        }
-
-        /**
-         * @param key Key to clear.
-         * @param cacheName Cache name.
-         */
-        private ClearKeyCallable(Object key, String cacheName) {
-            this.key = key;
-            this.cacheName = cacheName;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Void call() throws IgniteCheckedException {
-            IgniteInternalCache<Object, Object> cache = ((IgniteKernal)ignite).getCache(cacheName);
-
-            assert cache != null;
-
-            cache.clearLocally(key);
-
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            out.writeObject(key);
-
-            U.writeString(out, cacheName);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            key = in.readObject();
-
-            cacheName = U.readString(in);
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateCacheProxy.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateCacheProxy.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateCacheProxy.java
deleted file mode 100644
index 7204083..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateCacheProxy.java
+++ /dev/null
@@ -1,801 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import javax.cache.Cache;
-import javax.cache.expiry.ExpiryPolicy;
-import javax.cache.processor.EntryProcessor;
-import javax.cache.processor.EntryProcessorResult;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.cache.CacheEntry;
-import org.apache.ignite.cache.CacheMetrics;
-import org.apache.ignite.cache.CachePeekMode;
-import org.apache.ignite.cache.affinity.Affinity;
-import org.apache.ignite.cluster.ClusterGroup;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
-import org.apache.ignite.internal.processors.cache.CacheEntryPredicate;
-import org.apache.ignite.internal.processors.cache.GridCacheContext;
-import org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy;
-import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
-import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
-import org.apache.ignite.lang.IgniteBiPredicate;
-import org.apache.ignite.mxbean.CacheMetricsMXBean;
-import org.apache.ignite.transactions.Transaction;
-import org.apache.ignite.transactions.TransactionConcurrency;
-import org.apache.ignite.transactions.TransactionIsolation;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Hibernate cache proxy used to substitute hibernate keys with ignite keys.
- */
-public class HibernateCacheProxy implements IgniteInternalCache<Object, Object> {
-    /** Delegate. */
-    private final IgniteInternalCache<Object, Object> delegate;
-
-    /** Transformer. */
-    private final HibernateKeyTransformer keyTransformer;
-
-    /**
-     * @param delegate Delegate.
-     * @param keyTransformer Key keyTransformer.
-     */
-    HibernateCacheProxy(
-        IgniteInternalCache<Object, Object> delegate,
-        HibernateKeyTransformer keyTransformer
-    ) {
-        assert delegate != null;
-        assert keyTransformer != null;
-
-        this.delegate = delegate;
-        this.keyTransformer = keyTransformer;
-    }
-
-    /**
-     * @return HibernateKeyTransformer
-     */
-    HibernateKeyTransformer keyTransformer(){
-        return keyTransformer;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String name() {
-        return delegate.name();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean skipStore() {
-        return delegate.skipStore();
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalCache setSkipStore(boolean skipStore) {
-        return delegate.setSkipStore(skipStore);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isEmpty() {
-        return delegate.isEmpty();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean containsKey(Object key) {
-        return delegate.containsKey(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> containsKeyAsync(Object key) {
-        return delegate.containsKeyAsync(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean containsKeys(Collection keys) {
-        return delegate.containsKey(transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> containsKeysAsync(Collection keys) {
-        return delegate.containsKeysAsync(transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object localPeek(
-        Object key,
-        CachePeekMode[] peekModes,
-        @Nullable IgniteCacheExpiryPolicy plc
-    ) throws IgniteCheckedException {
-        return delegate.localPeek(keyTransformer.transform(key), peekModes, plc);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Iterable<Cache.Entry<Object, Object>> localEntries(
-        CachePeekMode[] peekModes
-    ) throws IgniteCheckedException {
-        return delegate.localEntries(peekModes);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object get(Object key) throws IgniteCheckedException {
-        return delegate.get(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public CacheEntry getEntry(Object key) throws IgniteCheckedException {
-        return delegate.getEntry(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture getAsync(Object key) {
-        return delegate.getAsync(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<CacheEntry<Object, Object>> getEntryAsync(Object key) {
-        return delegate.getEntryAsync(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Map getAll(@Nullable Collection keys) throws IgniteCheckedException {
-        return delegate.getAll(transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<CacheEntry<Object, Object>> getEntries(
-        @Nullable Collection keys) throws IgniteCheckedException {
-        return delegate.getEntries(transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Map<Object, Object>> getAllAsync(@Nullable Collection keys) {
-        return delegate.getAllAsync(transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Collection<CacheEntry<Object,Object>>> getEntriesAsync(
-        @Nullable Collection keys
-    ) {
-        return delegate.getEntriesAsync(transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object getAndPut(Object key, Object val) throws IgniteCheckedException {
-        return delegate.getAndPut(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture getAndPutAsync(Object key, Object val) {
-        return delegate.getAndPutAsync(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean put(Object key, Object val) throws IgniteCheckedException {
-        return delegate.put(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> putAsync(Object key, Object val) {
-        return delegate.putAsync(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object getAndPutIfAbsent(Object key, Object val) throws IgniteCheckedException {
-        return delegate.getAndPutIfAbsent(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture getAndPutIfAbsentAsync(Object key, Object val) {
-        return delegate.getAndPutIfAbsentAsync(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean putIfAbsent(Object key, Object val) throws IgniteCheckedException {
-        return delegate.putIfAbsent(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> putIfAbsentAsync(Object key, Object val) {
-        return delegate.putIfAbsentAsync(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object getAndReplace(Object key, Object val) throws IgniteCheckedException {
-        return delegate.getAndReplace(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture getAndReplaceAsync(Object key, Object val) {
-        return delegate.getAndReplaceAsync(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean replace(Object key, Object val) throws IgniteCheckedException {
-        return delegate.replace(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> replaceAsync(Object key, Object val) {
-        return delegate.replaceAsync(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean replace(Object key, Object oldVal, Object newVal) throws IgniteCheckedException {
-        return delegate.replace(keyTransformer.transform(key), oldVal, newVal);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> replaceAsync(Object key, Object oldVal, Object newVal) {
-        return delegate.replaceAsync(keyTransformer.transform(key), oldVal, newVal);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void putAll(@Nullable Map m) throws IgniteCheckedException {
-        delegate.putAll(transform(m));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<?> putAllAsync(@Nullable Map m) {
-        return delegate.putAllAsync(transform(m));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Set keySet() {
-        return delegate.keySet();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Set keySetx() {
-        return delegate.keySetx();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Set primaryKeySet() {
-        return delegate.primaryKeySet();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Iterable values() {
-        return delegate.values();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Set<Cache.Entry<Object, Object>> entrySet() {
-        return delegate.entrySet();
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Set<Cache.Entry<Object,Object>> entrySet(int part) {
-        return delegate.entrySet(part);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Set<Cache.Entry<Object, Object>> entrySetx(CacheEntryPredicate... filter) {
-        return delegate.entrySetx(filter);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Transaction txStart(
-        TransactionConcurrency concurrency,
-        TransactionIsolation isolation
-    ) {
-        return delegate.txStart(concurrency, isolation);
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridNearTxLocal txStartEx(
-        TransactionConcurrency concurrency,
-        TransactionIsolation isolation
-    ) {
-        return delegate.txStartEx(concurrency, isolation);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Transaction txStart(
-        TransactionConcurrency concurrency,
-        TransactionIsolation isolation,
-        long timeout,
-        int txSize
-    ) {
-        return delegate.txStart(concurrency, isolation, timeout, txSize);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public GridNearTxLocal tx() {
-        return delegate.tx();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean evict(Object key) {
-        return delegate.evict(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void evictAll(@Nullable Collection keys) {
-        delegate.evictAll(transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void clearLocally(boolean srv, boolean near, boolean readers) {
-        delegate.clearLocally(srv, near, readers);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean clearLocally(Object key) {
-        return delegate.clearLocally(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void clearLocallyAll(Set keys, boolean srv, boolean near, boolean readers) {
-        delegate.clearLocallyAll((Set<?>)transform(keys), srv, near, readers);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void clear(Object key) throws IgniteCheckedException {
-        delegate.clear(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void clearAll(Set keys) throws IgniteCheckedException {
-        delegate.clearAll((Set<?>)transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void clear() throws IgniteCheckedException {
-        delegate.clear();
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<?> clearAsync() {
-        return delegate.clearAsync();
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<?> clearAsync(Object key) {
-        return delegate.clearAsync(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<?> clearAllAsync(Set keys) {
-        return delegate.clearAllAsync((Set<?>)transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object getAndRemove(Object key) throws IgniteCheckedException {
-        return delegate.getAndRemove(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture getAndRemoveAsync(Object key) {
-        return delegate.getAndRemoveAsync(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean remove(Object key) throws IgniteCheckedException {
-        return delegate.remove(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> removeAsync(Object key) {
-        return delegate.removeAsync(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean remove(Object key, Object val) throws IgniteCheckedException {
-        return delegate.remove(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> removeAsync(Object key, Object val) {
-        return delegate.removeAsync(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void removeAll(@Nullable Collection keys) throws IgniteCheckedException {
-        delegate.removeAll(transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<?> removeAllAsync(@Nullable Collection keys) {
-        return delegate.removeAllAsync(transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void removeAll() throws IgniteCheckedException {
-        delegate.removeAll();
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<?> removeAllAsync() {
-        return delegate.removeAllAsync();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean lock(Object key, long timeout) throws IgniteCheckedException {
-        return delegate.lock(keyTransformer.transform(key), timeout);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> lockAsync(Object key, long timeout) {
-        return delegate.lockAsync(keyTransformer.transform(key), timeout);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean lockAll(@Nullable Collection keys, long timeout) throws IgniteCheckedException {
-        return delegate.lockAll(transform(keys), timeout);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> lockAllAsync(@Nullable Collection keys, long timeout) {
-        return delegate.lockAllAsync(transform(keys), timeout);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unlock(Object key) throws IgniteCheckedException {
-        delegate.unlock(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unlockAll(@Nullable Collection keys) throws IgniteCheckedException {
-        delegate.unlockAll(transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isLocked(Object key) {
-        return delegate.isLocked(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isLockedByThread(Object key) {
-        return delegate.isLockedByThread(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        return delegate.size();
-    }
-
-    /** {@inheritDoc} */
-    @Override public long sizeLong() {
-        return delegate.sizeLong();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int localSize(CachePeekMode[] peekModes) throws IgniteCheckedException {
-        return delegate.localSize(peekModes);
-    }
-
-    /** {@inheritDoc} */
-    @Override public long localSizeLong(CachePeekMode[] peekModes) throws IgniteCheckedException {
-        return delegate.localSizeLong(peekModes);
-    }
-
-    /** {@inheritDoc} */
-    @Override public long localSizeLong(int partition, CachePeekMode[] peekModes) throws IgniteCheckedException {
-        return delegate.localSizeLong(partition, peekModes);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size(CachePeekMode[] peekModes) throws IgniteCheckedException {
-        return delegate.size(peekModes);
-    }
-
-    /** {@inheritDoc} */
-    @Override public long sizeLong(CachePeekMode[] peekModes) throws IgniteCheckedException {
-        return delegate.sizeLong(peekModes);
-    }
-
-    /** {@inheritDoc} */
-    @Override public long sizeLong(int partition, CachePeekMode[] peekModes) throws IgniteCheckedException {
-        return delegate.sizeLong(partition, peekModes);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Integer> sizeAsync(CachePeekMode[] peekModes) {
-        return delegate.sizeAsync(peekModes);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Long> sizeLongAsync(CachePeekMode[] peekModes) {
-        return delegate.sizeLongAsync(peekModes);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Long> sizeLongAsync(int partition, CachePeekMode[] peekModes) {
-        return delegate.sizeLongAsync(partition, peekModes);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int nearSize() {
-        return delegate.nearSize();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int primarySize() {
-        return delegate.primarySize();
-    }
-
-    /** {@inheritDoc} */
-    @Override public long primarySizeLong() {
-        return delegate.primarySizeLong();
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheConfiguration configuration() {
-        return delegate.configuration();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Affinity affinity() {
-        return delegate.affinity();
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheMetrics clusterMetrics() {
-        return delegate.clusterMetrics();
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheMetrics clusterMetrics(ClusterGroup grp) {
-        return delegate.clusterMetrics(grp);
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheMetrics localMetrics() {
-        return delegate.localMetrics();
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheMetricsMXBean clusterMxBean() {
-        return delegate.clusterMxBean();
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheMetricsMXBean localMxBean() {
-        return delegate.localMxBean();
-    }
-
-    /** {@inheritDoc} */
-    @Override public long offHeapEntriesCount() {
-        return delegate.offHeapEntriesCount();
-    }
-
-    /** {@inheritDoc} */
-    @Override public long offHeapAllocatedSize() {
-        return delegate.offHeapAllocatedSize();
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<?> rebalance() {
-        return delegate.rebalance();
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalCache forSubjectId(UUID subjId) {
-        return delegate.forSubjectId(subjId);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object getForcePrimary(Object key) throws IgniteCheckedException {
-        return delegate.getForcePrimary(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture getForcePrimaryAsync(Object key) {
-        return delegate.getForcePrimaryAsync(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Map getAllOutTx(Set keys) throws IgniteCheckedException {
-        return delegate.getAllOutTx((Set<?>)transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Map<Object, Object>> getAllOutTxAsync(Set keys) {
-        return delegate.getAllOutTxAsync((Set<?>)transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isIgfsDataCache() {
-        return delegate.isIgfsDataCache();
-    }
-
-    /** {@inheritDoc} */
-    @Override public long igfsDataSpaceUsed() {
-        return delegate.igfsDataSpaceUsed();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isMongoDataCache() {
-        return delegate.isMongoDataCache();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isMongoMetaCache() {
-        return delegate.isMongoMetaCache();
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public ExpiryPolicy expiry() {
-        return delegate.expiry();
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalCache withExpiryPolicy(ExpiryPolicy plc) {
-        return delegate.withExpiryPolicy(plc);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalCache withNoRetries() {
-        return delegate.withNoRetries();
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridCacheContext context() {
-        return delegate.context();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void localLoadCache(
-        @Nullable IgniteBiPredicate p,
-        @Nullable Object... args
-    ) throws IgniteCheckedException {
-        delegate.localLoadCache(p, args);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<?> localLoadCacheAsync(
-        @Nullable IgniteBiPredicate p,
-        @Nullable Object... args
-    ) {
-        return delegate.localLoadCacheAsync(p, args);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object getTopologySafe(Object key) throws IgniteCheckedException {
-        return delegate.getTopologySafe(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<Integer> lostPartitions() {
-        return delegate.lostPartitions();
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public EntryProcessorResult invoke(
-        @Nullable AffinityTopologyVersion topVer,
-        Object key,
-        EntryProcessor entryProcessor,
-        Object... args
-    ) throws IgniteCheckedException {
-        return delegate.invoke(topVer, key, entryProcessor, args);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Map> invokeAllAsync(Map map, Object... args) {
-        return delegate.invokeAllAsync(map, args);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Map invokeAll(Map map, Object... args) throws IgniteCheckedException {
-        return delegate.invokeAll(map, args);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Map> invokeAllAsync(Set keys, EntryProcessor entryProcessor, Object... args) {
-        return delegate.invokeAllAsync((Set<?>)transform(keys), entryProcessor, args);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Map invokeAll(Set keys, EntryProcessor entryProcessor, Object... args) throws IgniteCheckedException {
-        return delegate.invokeAll((Set<?>)transform(keys), entryProcessor, args);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<EntryProcessorResult> invokeAsync(
-        Object key,
-        EntryProcessor entryProcessor,
-        Object... args
-    ) {
-        return delegate.invokeAsync(keyTransformer.transform(key), entryProcessor, args);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public EntryProcessorResult invoke(
-        Object key,
-        EntryProcessor entryProcessor,
-        Object... args
-    ) throws IgniteCheckedException {
-        return delegate.invoke(keyTransformer.transform(key), entryProcessor, args);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Iterator<Cache.Entry<Object,Object>> scanIterator(
-        boolean keepBinary,
-        @Nullable IgniteBiPredicate p
-    ) throws IgniteCheckedException {
-        return delegate.scanIterator(keepBinary, p);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<?> removeAllConflictAsync(Map drMap) throws IgniteCheckedException {
-        return delegate.removeAllConflictAsync(drMap);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void removeAllConflict(Map drMap) throws IgniteCheckedException {
-        delegate.removeAllConflictAsync(drMap);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<?> putAllConflictAsync(Map drMap) throws IgniteCheckedException {
-        return delegate.putAllConflictAsync(drMap);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void putAllConflict(Map drMap) throws IgniteCheckedException {
-        delegate.putAllConflict(drMap);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalCache keepBinary() {
-        return delegate.keepBinary();
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalCache cache() {
-        return delegate.cache();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Iterator iterator() {
-        return delegate.iterator();
-    }
-
-    /**
-     * @param keys Keys.
-     */
-    private Collection<Object> transform(Collection<Object> keys) {
-        Collection<Object> res = new LinkedList<>();
-
-        for (Object o : keys)
-            res.add(keyTransformer.transform(o));
-
-        return res;
-    }
-
-    /**
-     * @param map Map.
-     */
-    private Map<Object, Object> transform(Map<Object, Object> map) {
-        Map<Object, Object> res = new HashMap<>();
-
-        Set<Map.Entry<Object, Object>> ents = map.entrySet();
-
-        for (Map.Entry<Object, Object> e : ents)
-            res.put(keyTransformer.transform(e.getKey()), e.getValue());
-
-        return res;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java
deleted file mode 100644
index be99e98..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.apache.ignite.Ignite;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.CacheDataDescription;
-import org.hibernate.cache.spi.CollectionRegion;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
-import org.hibernate.engine.spi.SessionFactoryImplementor;
-import org.hibernate.persister.collection.CollectionPersister;
-
-/**
- * Implementation of {@link CollectionRegion}. This region is used to store collection data.
- * <p>
- * L2 cache for collection can be enabled in the Hibernate configuration file:
- * <pre name="code" class="xml">
- * &lt;hibernate-configuration&gt;
- *     &lt;!-- Enable L2 cache. --&gt;
- *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
- *
- *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
- *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
- *
- *     &lt;!-- Specify entities. --&gt;
- *     &lt;mapping class="com.example.Entity"/&gt;
- *     &lt;mapping class="com.example.ChildEntity"/&gt;
- *
- *     &lt;!-- Enable L2 cache with nonstrict-read-write access strategy for entities and collection. --&gt;
- *     &lt;collection-cache collection="com.example.Entity" usage="nonstrict-read-write"/&gt;
- *     &lt;collection-cache collection="com.example.ChildEntity" usage="nonstrict-read-write"/&gt;
- *     &lt;collection-cache collection="com.example.Entity.children" usage="nonstrict-read-write"/&gt;
- * &lt;/hibernate-configuration&gt;
- * </pre>
- * Also cache for collection can be enabled using annotations:
- * <pre name="code" class="java">
- * &#064;javax.persistence.Entity
- * public class Entity {
- *    ...
- *
- *    &#064;javax.persistence.OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
- *    &#064;javax.persistence.JoinColumn(name="PARENT_ID")
- *    &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
- *    public List&lt;ChildEntity&gt; getChildren() {...}
- * }
- * </pre>
- * Note: the collection cache does not cache the state of the actual entities in the cache, it caches only identifier
- * values. For this reason, the collection cache should always be used in conjunction with
- * the second-level cache for those entities expected to be cached as part of a collection cache.
- */
-public class HibernateCollectionRegion extends HibernateTransactionalDataRegion implements CollectionRegion {
-    /**
-     * @param factory Region factory.
-     * @param name Region name.
-     * @param ignite Grid.
-     * @param cache Region cache.
-     * @param dataDesc Region data description.
-     */
-    public HibernateCollectionRegion(HibernateRegionFactory factory, String name,
-        Ignite ignite, HibernateCacheProxy cache, CacheDataDescription dataDesc) {
-        super(factory, name, ignite, cache, dataDesc);
-    }
-
-    /** {@inheritDoc} */
-    @Override public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
-        return new AccessStrategy(createAccessStrategy(accessType));
-    }
-
-    /**
-     * Collection region access strategy.
-     */
-    private class AccessStrategy extends HibernateAbstractRegionAccessStrategy
-        implements CollectionRegionAccessStrategy {
-        /**
-         * @param stgy Access strategy implementation.
-         */
-        private AccessStrategy(HibernateAccessStrategyAdapter stgy) {
-            super(stgy);
-        }
-
-        /** {@inheritDoc} */
-        @Override public Object generateCacheKey(Object id,
-            CollectionPersister persister,
-            SessionFactoryImplementor factory, String tenantIdentifier) {
-            return HibernateKeyWrapper.staticCreateCollectionKey(id, persister, tenantIdentifier);
-        }
-
-        /** {@inheritDoc} */
-        @Override public Object getCacheKeyId(Object cacheKey) {
-            return ((HibernateKeyWrapper)cacheKey).id();
-        }
-
-        /** {@inheritDoc} */
-        @Override public CollectionRegion getRegion() {
-            return HibernateCollectionRegion.this;
-        }
-    }
-}
\ No newline at end of file


[12/16] ignite git commit: ignite-1794 Refactored hibernate modules, switched to hibernate 5.1

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java
new file mode 100644
index 0000000..6e546b0
--- /dev/null
+++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java
@@ -0,0 +1,543 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.store.hibernate;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.cache.integration.CacheLoaderException;
+import javax.cache.integration.CacheWriterException;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cache.store.CacheStore;
+import org.apache.ignite.cache.store.CacheStoreAdapter;
+import org.apache.ignite.cache.store.CacheStoreSession;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.util.tostring.GridToStringExclude;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.marshaller.jdk.JdkMarshaller;
+import org.apache.ignite.resources.CacheStoreSessionResource;
+import org.apache.ignite.resources.IgniteInstanceResource;
+import org.apache.ignite.resources.LoggerResource;
+import org.apache.ignite.transactions.Transaction;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.SharedSessionContract;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.resource.transaction.spi.TransactionStatus;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * {@link CacheStore} implementation backed by Hibernate. This implementation
+ * stores objects in underlying database in {@code BLOB} format.
+ * <h2 class="header">Configuration</h2>
+ * Either {@link #setSessionFactory(SessionFactory)} or
+ * {@link #setHibernateConfigurationPath(String)} or
+ * {@link #setHibernateProperties(Properties)} should be set.
+ * <p>
+ * If session factory is provided it should contain
+ * {@link CacheHibernateBlobStoreEntry} persistent class (via provided
+ * mapping file {@code GridCacheHibernateStoreEntry.hbm.xml} or by
+ * adding {@link CacheHibernateBlobStoreEntry} to annotated classes
+ * of session factory.
+ * <p>
+ * Path to hibernate configuration may be either an URL or a file path or
+ * a classpath resource. This configuration file should include provided
+ * mapping {@code GridCacheHibernateStoreEntry.hbm.xml} or include annotated
+ * class {@link CacheHibernateBlobStoreEntry}.
+ * <p>
+ * If hibernate properties are provided, mapping
+ * {@code GridCacheHibernateStoreEntry.hbm.xml} is included automatically.
+ * <p>
+ * Use {@link CacheHibernateBlobStoreFactory} factory to pass {@link CacheHibernateBlobStore} to {@link CacheConfiguration}.
+ */
+public class CacheHibernateBlobStore<K, V> extends CacheStoreAdapter<K, V> {
+    /**
+     * Default connection URL
+     * (value is <tt>jdbc:h2:mem:hibernateCacheStore;DB_CLOSE_DELAY=-1;DEFAULT_LOCK_TIMEOUT=5000</tt>).
+     */
+    public static final String DFLT_CONN_URL = "jdbc:h2:mem:hibernateCacheStore;DB_CLOSE_DELAY=-1;" +
+        "DEFAULT_LOCK_TIMEOUT=5000";
+
+    /** Default show SQL property value (value is <tt>true</tt>). */
+    public static final String DFLT_SHOW_SQL = "true";
+
+    /** Default <tt>hibernate.hbm2ddl.auto</tt> property value (value is <tt>true</tt>). */
+    public static final String DFLT_HBM2DDL_AUTO = "update";
+
+    /** Session attribute name. */
+    private static final String ATTR_SES = "HIBERNATE_STORE_SESSION";
+
+    /** Name of Hibarname mapping resource. */
+    private static final String MAPPING_RESOURCE =
+            "org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml";
+
+    /** Marshaller. */
+    private static final Marshaller marsh = new JdkMarshaller();
+
+    /** Init guard. */
+    @GridToStringExclude
+    private final AtomicBoolean initGuard = new AtomicBoolean();
+
+    /** Init latch. */
+    @GridToStringExclude
+    private final CountDownLatch initLatch = new CountDownLatch(1);
+
+    /** Hibernate properties. */
+    @GridToStringExclude
+    private Properties hibernateProps;
+
+    /** Session factory. */
+    @GridToStringExclude
+    private SessionFactory sesFactory;
+
+    /** Path to hibernate configuration file. */
+    private String hibernateCfgPath;
+
+    /** Log. */
+    @LoggerResource
+    private IgniteLogger log;
+
+    /** Auto-injected store session. */
+    @CacheStoreSessionResource
+    private CacheStoreSession ses;
+
+    /** Ignite instance. */
+    @IgniteInstanceResource
+    private Ignite ignite;
+
+    /** {@inheritDoc} */
+    @SuppressWarnings({"unchecked", "RedundantTypeArguments"})
+    @Override public V load(K key) {
+        init();
+
+        Transaction tx = transaction();
+
+        if (log.isDebugEnabled())
+            log.debug("Store load [key=" + key + ", tx=" + tx + ']');
+
+        Session ses = session(tx);
+
+        try {
+            CacheHibernateBlobStoreEntry entry = (CacheHibernateBlobStoreEntry)
+                ses.get(CacheHibernateBlobStoreEntry.class, toBytes(key));
+
+            if (entry == null)
+                return null;
+
+            return fromBytes(entry.getValue());
+        }
+        catch (IgniteCheckedException | HibernateException e) {
+            rollback(ses, tx);
+
+            throw new CacheLoaderException("Failed to load value from cache store with key: " + key, e);
+        }
+        finally {
+            end(ses, tx);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void write(javax.cache.Cache.Entry<? extends K, ? extends V> entry) {
+        init();
+
+        Transaction tx = transaction();
+
+        K key = entry.getKey();
+        V val = entry.getValue();
+
+        if (log.isDebugEnabled())
+            log.debug("Store put [key=" + key + ", val=" + val + ", tx=" + tx + ']');
+
+        if (val == null) {
+            delete(key);
+
+            return;
+        }
+
+        Session ses = session(tx);
+
+        try {
+            CacheHibernateBlobStoreEntry entry0 = new CacheHibernateBlobStoreEntry(toBytes(key), toBytes(val));
+
+            ses.saveOrUpdate(entry0);
+        }
+        catch (IgniteCheckedException | HibernateException e) {
+            rollback(ses, tx);
+
+            throw new CacheWriterException("Failed to put value to cache store [key=" + key + ", val" + val + "]", e);
+        }
+        finally {
+            end(ses, tx);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings({"JpaQueryApiInspection", "JpaQlInspection"})
+    @Override public void delete(Object key) {
+        init();
+
+        Transaction tx = transaction();
+
+        if (log.isDebugEnabled())
+            log.debug("Store remove [key=" + key + ", tx=" + tx + ']');
+
+        Session ses = session(tx);
+
+        try {
+            Object obj = ses.get(CacheHibernateBlobStoreEntry.class, toBytes(key));
+
+            if (obj != null)
+                ses.delete(obj);
+        }
+        catch (IgniteCheckedException | HibernateException e) {
+            rollback(ses, tx);
+
+            throw new CacheWriterException("Failed to remove value from cache store with key: " + key, e);
+        }
+        finally {
+            end(ses, tx);
+        }
+    }
+
+    /**
+     * Rolls back hibernate session.
+     *
+     * @param ses Hibernate session.
+     * @param tx Cache ongoing transaction.
+     */
+    private void rollback(SharedSessionContract ses, Transaction tx) {
+        // Rollback only if there is no cache transaction,
+        // otherwise sessionEnd() will do all required work.
+        if (tx == null) {
+            org.hibernate.Transaction hTx = ses.getTransaction();
+
+            if (hTx != null && hTx.getStatus().canRollback())
+                hTx.rollback();
+        }
+    }
+
+    /**
+     * Ends hibernate session.
+     *
+     * @param ses Hibernate session.
+     * @param tx Cache ongoing transaction.
+     */
+    private void end(Session ses, Transaction tx) {
+        // Commit only if there is no cache transaction,
+        // otherwise sessionEnd() will do all required work.
+        if (tx == null) {
+            org.hibernate.Transaction hTx = ses.getTransaction();
+
+            if (hTx != null && hTx.getStatus() == TransactionStatus.ACTIVE)
+                hTx.commit();
+
+            ses.close();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void sessionEnd(boolean commit) {
+        init();
+
+        Transaction tx = transaction();
+
+        Map<String, Session> props = session().properties();
+
+        Session ses = props.remove(ATTR_SES);
+
+        if (ses != null) {
+            org.hibernate.Transaction hTx = ses.getTransaction();
+
+            if (hTx != null) {
+                try {
+                    if (commit) {
+                        ses.flush();
+
+                        hTx.commit();
+                    }
+                    else
+                        hTx.rollback();
+
+                    if (log.isDebugEnabled())
+                        log.debug("Transaction ended [xid=" + tx.xid() + ", commit=" + commit + ']');
+                }
+                catch (HibernateException e) {
+                    throw new CacheWriterException("Failed to end transaction [xid=" + tx.xid() +
+                        ", commit=" + commit + ']', e);
+                }
+                finally {
+                    ses.close();
+                }
+            }
+        }
+    }
+
+    /**
+     * Gets Hibernate session.
+     *
+     * @param tx Cache transaction.
+     * @return Session.
+     */
+    Session session(@Nullable Transaction tx) {
+        Session ses;
+
+        if (tx != null) {
+            Map<String, Session> props = session().properties();
+
+            ses = props.get(ATTR_SES);
+
+            if (ses == null) {
+                ses = sesFactory.openSession();
+
+                ses.beginTransaction();
+
+                // Store session in transaction metadata, so it can be accessed
+                // for other operations on the same transaction.
+                props.put(ATTR_SES, ses);
+
+                if (log.isDebugEnabled())
+                    log.debug("Hibernate session open [ses=" + ses + ", tx=" + tx.xid() + "]");
+            }
+        }
+        else {
+            ses = sesFactory.openSession();
+
+            ses.beginTransaction();
+        }
+
+        return ses;
+    }
+
+    /**
+     * Sets session factory.
+     *
+     * @param sesFactory Session factory.
+     */
+    public void setSessionFactory(SessionFactory sesFactory) {
+        this.sesFactory = sesFactory;
+    }
+
+    /**
+     * Sets hibernate configuration path.
+     * <p>
+     * This may be either URL or file path or classpath resource.
+     *
+     * @param hibernateCfgPath URL or file path or classpath resource
+     *      pointing to hibernate configuration XML file.
+     */
+    public void setHibernateConfigurationPath(String hibernateCfgPath) {
+        this.hibernateCfgPath = hibernateCfgPath;
+    }
+
+    /**
+     * Sets Hibernate properties.
+     *
+     * @param hibernateProps Hibernate properties.
+     */
+    public void setHibernateProperties(Properties hibernateProps) {
+        this.hibernateProps = hibernateProps;
+    }
+
+    /**
+     * Initializes store.
+     *
+     * @throws IgniteException If failed to initialize.
+     */
+    private void init() throws IgniteException {
+        if (initGuard.compareAndSet(false, true)) {
+            if (log.isDebugEnabled())
+                log.debug("Initializing cache store.");
+
+            try {
+                if (sesFactory != null)
+                    // Session factory has been provided - nothing to do.
+                    return;
+
+                if (!F.isEmpty(hibernateCfgPath)) {
+                    try {
+                        URL url = new URL(hibernateCfgPath);
+
+                        sesFactory = new Configuration().configure(url).buildSessionFactory();
+
+                        if (log.isDebugEnabled())
+                            log.debug("Configured session factory using URL: " + url);
+
+                        // Session factory has been successfully initialized.
+                        return;
+                    }
+                    catch (MalformedURLException e) {
+                        if (log.isDebugEnabled())
+                            log.debug("Caught malformed URL exception: " + e.getMessage());
+                    }
+
+                    // Provided path is not a valid URL. File?
+                    File cfgFile = new File(hibernateCfgPath);
+
+                    if (cfgFile.exists()) {
+                        sesFactory = new Configuration().configure(cfgFile).buildSessionFactory();
+
+                        if (log.isDebugEnabled())
+                            log.debug("Configured session factory using file: " + hibernateCfgPath);
+
+                        // Session factory has been successfully initialized.
+                        return;
+                    }
+
+                    // Provided path is not a file. Classpath resource?
+                    sesFactory = new Configuration().configure(hibernateCfgPath).buildSessionFactory();
+
+                    if (log.isDebugEnabled())
+                        log.debug("Configured session factory using classpath resource: " + hibernateCfgPath);
+                }
+                else {
+                    if (hibernateProps == null) {
+                        U.warn(log, "No Hibernate configuration has been provided for store (will use default).");
+
+                        hibernateProps = new Properties();
+
+                        hibernateProps.setProperty("hibernate.connection.url", DFLT_CONN_URL);
+                        hibernateProps.setProperty("hibernate.show_sql", DFLT_SHOW_SQL);
+                        hibernateProps.setProperty("hibernate.hbm2ddl.auto", DFLT_HBM2DDL_AUTO);
+                    }
+
+                    Configuration cfg = new Configuration();
+
+                    cfg.setProperties(hibernateProps);
+
+                    assert resourceAvailable(MAPPING_RESOURCE) : MAPPING_RESOURCE;
+
+                    cfg.addResource(MAPPING_RESOURCE);
+
+                    sesFactory = cfg.buildSessionFactory();
+
+                    if (log.isDebugEnabled())
+                        log.debug("Configured session factory using properties: " + hibernateProps);
+                }
+            }
+            catch (HibernateException e) {
+                throw new IgniteException("Failed to initialize store.", e);
+            }
+            finally {
+                initLatch.countDown();
+            }
+        }
+        else if (initLatch.getCount() > 0) {
+            try {
+                U.await(initLatch);
+            }
+            catch (IgniteInterruptedCheckedException e) {
+                throw new IgniteException(e);
+            }
+        }
+
+        if (sesFactory == null)
+            throw new IgniteException("Cache store was not properly initialized.");
+    }
+
+    /**
+     * Checks availability of a classpath resource.
+     *
+     * @param name Resource name.
+     * @return {@code true} if resource is available and ready for read, {@code false} otherwise.
+     */
+    private boolean resourceAvailable(String name) {
+        InputStream cfgStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
+
+        if (cfgStream == null) {
+            log.error("Classpath resource not found: " + name);
+
+            return false;
+        }
+
+        try {
+            // Read a single byte to force actual content access by JVM.
+            cfgStream.read();
+
+            return true;
+        }
+        catch (IOException e) {
+            log.error("Failed to read classpath resource: " + name, e);
+
+            return false;
+        }
+        finally {
+            U.close(cfgStream, log);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(CacheHibernateBlobStore.class, this);
+    }
+
+    /**
+     * Serialize object to byte array using marshaller.
+     *
+     * @param obj Object to convert to byte array.
+     * @return Byte array.
+     * @throws IgniteCheckedException If failed to convert.
+     */
+    protected byte[] toBytes(Object obj) throws IgniteCheckedException {
+        return U.marshal(marsh, obj);
+    }
+
+    /**
+     * Deserialize object from byte array using marshaller.
+     *
+     * @param bytes Bytes to deserialize.
+     * @param <X> Result object type.
+     * @return Deserialized object.
+     * @throws IgniteCheckedException If failed.
+     */
+    protected <X> X fromBytes(byte[] bytes) throws IgniteCheckedException {
+        if (bytes == null || bytes.length == 0)
+            return null;
+
+        return U.unmarshal(marsh, bytes, getClass().getClassLoader());
+    }
+
+    /**
+     * @return Current transaction.
+     */
+    @Nullable private Transaction transaction() {
+        CacheStoreSession ses = session();
+
+        return ses != null ? ses.transaction() : null;
+    }
+
+    /**
+     * @return Store session.
+     */
+    private CacheStoreSession session() {
+        return ses;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml
new file mode 100644
index 0000000..5b0be43
--- /dev/null
+++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+
+<!DOCTYPE hibernate-mapping PUBLIC
+        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.apache.ignite.examples.datagrid.store" default-access="field">
+    <class name="org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreEntry" table="ENTRIES">
+        <id name="key"/>
+
+        <property name="val"/>
+    </class>
+</hibernate-mapping>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.java
new file mode 100644
index 0000000..d40c5ef
--- /dev/null
+++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.store.hibernate;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+/**
+ * Entry that is used by {@link CacheHibernateBlobStore} implementation.
+ * <p>
+ * Note that this is a reference implementation for tests only.
+ * When running on production systems use concrete key-value types to
+ * get better performance.
+ */
+@Entity
+@Table(name = "ENTRIES")
+public class CacheHibernateBlobStoreEntry {
+    /** Key (use concrete key type in production). */
+    @Id
+    @Column(length = 65535)
+    private byte[] key;
+
+    /** Value (use concrete value type in production). */
+    @Column(length = 65535)
+    private byte[] val;
+
+    /**
+     * Constructor.
+     */
+    CacheHibernateBlobStoreEntry() {
+        // No-op.
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param key Key.
+     * @param val Value.
+     */
+    CacheHibernateBlobStoreEntry(byte[] key, byte[] val) {
+        this.key = key;
+        this.val = val;
+    }
+
+    /**
+     * @return Key.
+     */
+    public byte[] getKey() {
+        return key;
+    }
+
+    /**
+     * @param key Key.
+     */
+    public void setKey(byte[] key) {
+        this.key = key;
+    }
+
+    /**
+     * @return Value.
+     */
+    public byte[] getValue() {
+        return val;
+    }
+
+    /**
+     * @param val Value.
+     */
+    public void setValue(byte[] val) {
+        this.val = val;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreFactory.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreFactory.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreFactory.java
new file mode 100644
index 0000000..ea4df8a
--- /dev/null
+++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreFactory.java
@@ -0,0 +1,235 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.store.hibernate;
+
+import java.util.Properties;
+import javax.cache.configuration.Factory;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.IgniteComponentType;
+import org.apache.ignite.internal.util.spring.IgniteSpringHelper;
+import org.apache.ignite.internal.util.tostring.GridToStringExclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.resources.SpringApplicationContextResource;
+import org.hibernate.SessionFactory;
+
+/**
+ * {@link Factory} implementation for {@link CacheHibernateBlobStore}.
+ *
+ * Use this factory to pass {@link CacheHibernateBlobStore} to {@link CacheConfiguration}.
+ *
+ * <h2 class="header">Java Example</h2>
+ * In this example existing session factory is provided.
+ * <pre name="code" class="java">
+ *     ...
+ *     CacheHibernateBlobStoreFactory&lt;String, String&gt; factory = new CacheHibernateBlobStoreFactory&lt;String, String&gt;();
+ *
+ *     factory.setSessionFactory(sesFactory);
+ *     ...
+ * </pre>
+ *
+ * <h2 class="header">Spring Example (using Spring ORM)</h2>
+ * <pre name="code" class="xml">
+ *   ...
+ *   &lt;bean id=&quot;cache.hibernate.store.factory&quot;
+ *       class=&quot;org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory&quot;&gt;
+ *       &lt;property name=&quot;sessionFactory&quot;&gt;
+ *           &lt;bean class=&quot;org.springframework.orm.hibernate3.LocalSessionFactoryBean&quot;&gt;
+ *               &lt;property name=&quot;hibernateProperties&quot;&gt;
+ *                   &lt;value&gt;
+ *                       connection.url=jdbc:h2:mem:
+ *                       show_sql=true
+ *                       hbm2ddl.auto=true
+ *                       hibernate.dialect=org.hibernate.dialect.H2Dialect
+ *                   &lt;/value&gt;
+ *               &lt;/property&gt;
+ *               &lt;property name=&quot;mappingResources&quot;&gt;
+ *                   &lt;list&gt;
+ *                       &lt;value&gt;
+ *                           org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml
+ *                       &lt;/value&gt;
+ *                   &lt;/list&gt;
+ *               &lt;/property&gt;
+ *           &lt;/bean&gt;
+ *       &lt;/property&gt;
+ *   &lt;/bean&gt;
+ *   ...
+ * </pre>
+ *
+ * <h2 class="header">Spring Example (using Spring ORM and persistent annotations)</h2>
+ * <pre name="code" class="xml">
+ *     ...
+ *     &lt;bean id=&quot;cache.hibernate.store.factory1&quot;
+ *         class=&quot;org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory&quot;&gt;
+ *         &lt;property name=&quot;sessionFactory&quot;&gt;
+ *             &lt;bean class=&quot;org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean&quot;&gt;
+ *                 &lt;property name=&quot;hibernateProperties&quot;&gt;
+ *                     &lt;value&gt;
+ *                         connection.url=jdbc:h2:mem:
+ *                         show_sql=true
+ *                         hbm2ddl.auto=true
+ *                         hibernate.dialect=org.hibernate.dialect.H2Dialect
+ *                     &lt;/value&gt;
+ *                 &lt;/property&gt;
+ *                 &lt;property name=&quot;annotatedClasses&quot;&gt;
+ *                     &lt;list&gt;
+ *                         &lt;value&gt;
+ *                             org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreEntry
+ *                         &lt;/value&gt;
+ *                     &lt;/list&gt;
+ *                 &lt;/property&gt;
+ *             &lt;/bean&gt;
+ *         &lt;/property&gt;
+ *     &lt;/bean&gt;
+ *     ...
+ * </pre>
+ *
+ * <h2 class="header">Spring Example</h2>
+ * <pre name="code" class="xml">
+ *     ...
+ *     &lt;bean id=&quot;cache.hibernate.store.factory2&quot;
+ *         class=&quot;org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory&quot;&gt;
+ *         &lt;property name=&quot;hibernateProperties&quot;&gt;
+ *             &lt;props&gt;
+ *                 &lt;prop key=&quot;connection.url&quot;&gt;jdbc:h2:mem:&lt;/prop&gt;
+ *                 &lt;prop key=&quot;hbm2ddl.auto&quot;&gt;update&lt;/prop&gt;
+ *                 &lt;prop key=&quot;show_sql&quot;&gt;true&lt;/prop&gt;
+ *             &lt;/props&gt;
+ *         &lt;/property&gt;
+ *     &lt;/bean&gt;
+ *     ...
+ * </pre>
+ * <p>
+ * <img src="http://ignite.apache.org/images/spring-small.png">
+ * <br>
+ * For information about Spring framework visit <a href="http://www.springframework.org/">www.springframework.org</a>
+ */
+public class CacheHibernateBlobStoreFactory<K, V> implements Factory<CacheHibernateBlobStore<K, V>> {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Session factory. */
+    @GridToStringExclude
+    private transient SessionFactory sesFactory;
+
+    /** Session factory bean name. */
+    private String sesFactoryBean;
+
+    /** Path to hibernate configuration file. */
+    private String hibernateCfgPath;
+
+    /** Hibernate properties. */
+    @GridToStringExclude
+    private Properties hibernateProps;
+
+    /** Application context. */
+    @SpringApplicationContextResource
+    private Object appContext;
+
+    /** {@inheritDoc} */
+    @Override public CacheHibernateBlobStore<K, V> create() {
+        CacheHibernateBlobStore<K, V> store = new CacheHibernateBlobStore<>();
+
+        store.setHibernateConfigurationPath(hibernateCfgPath);
+        store.setHibernateProperties(hibernateProps);
+
+        if (sesFactory != null)
+            store.setSessionFactory(sesFactory);
+        else if (sesFactoryBean != null) {
+            if (appContext == null)
+                throw new IgniteException("Spring application context resource is not injected.");
+
+            IgniteSpringHelper spring;
+
+            try {
+                spring = IgniteComponentType.SPRING.create(false);
+
+                SessionFactory sesFac = spring.loadBeanFromAppContext(appContext, sesFactoryBean);
+
+                store.setSessionFactory(sesFac);
+            }
+            catch (IgniteCheckedException e) {
+                throw new IgniteException("Failed to load bean in application context [beanName=" + sesFactoryBean +
+                        ", igniteConfig=" + appContext + ']');
+            }
+        }
+
+        return store;
+    }
+
+    /**
+     * Sets session factory.
+     *
+     * @param sesFactory Session factory.
+     * @return {@code This} for chaining.
+     * @see CacheHibernateBlobStore#setSessionFactory(SessionFactory)
+     */
+    public CacheHibernateBlobStoreFactory<K, V> setSessionFactory(SessionFactory sesFactory) {
+        this.sesFactory = sesFactory;
+
+        return this;
+    }
+
+    /**
+     * Sets name of the data source bean.
+     *
+     * @param sesFactory Session factory bean name.
+     * @return {@code This} for chaining.
+     * @see CacheHibernateBlobStore#setSessionFactory(SessionFactory)
+     */
+    public CacheHibernateBlobStoreFactory<K, V> setSessionFactoryBean(String sesFactory) {
+        this.sesFactoryBean = sesFactory;
+
+        return this;
+    }
+
+    /**
+     * Sets hibernate configuration path.
+     * <p>
+     * This may be either URL or file path or classpath resource.
+     *
+     * @param hibernateCfgPath URL or file path or classpath resource
+     *      pointing to hibernate configuration XML file.
+     * @return {@code This} for chaining.
+     * @see CacheHibernateBlobStore#setHibernateConfigurationPath(String)
+     */
+    public CacheHibernateBlobStoreFactory<K, V> setHibernateConfigurationPath(String hibernateCfgPath) {
+        this.hibernateCfgPath = hibernateCfgPath;
+
+        return this;
+    }
+
+    /**
+     * Sets Hibernate properties.
+     *
+     * @param hibernateProps Hibernate properties.
+     * @return {@code This} for chaining.
+     * @see CacheHibernateBlobStore#setHibernateProperties(Properties)
+     */
+    public CacheHibernateBlobStoreFactory<K, V> setHibernateProperties(Properties hibernateProps) {
+        this.hibernateProps = hibernateProps;
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(CacheHibernateBlobStoreFactory.class, this);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java
new file mode 100644
index 0000000..8db9568
--- /dev/null
+++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.store.hibernate;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import javax.cache.integration.CacheWriterException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cache.store.CacheStore;
+import org.apache.ignite.cache.store.CacheStoreSession;
+import org.apache.ignite.cache.store.CacheStoreSessionListener;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lifecycle.LifecycleAware;
+import org.apache.ignite.resources.LoggerResource;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.resource.transaction.spi.TransactionStatus;
+
+/**
+ * Hibernate-based cache store session listener.
+ * <p>
+ * This listener creates a new Hibernate session for each store
+ * session. If there is an ongoing cache transaction, a corresponding
+ * Hibernate transaction is created as well.
+ * <p>
+ * The Hibernate session is saved as a store session
+ * {@link CacheStoreSession#attachment() attachment}.
+ * The listener guarantees that the session will be
+ * available for any store operation. If there is an
+ * ongoing cache transaction, all operations within this
+ * transaction will share a DB transaction.
+ * <p>
+ * As an example, here is how the {@link CacheStore#write(javax.cache.Cache.Entry)}
+ * method can be implemented if {@link CacheHibernateStoreSessionListener}
+ * is configured:
+ * <pre name="code" class="java">
+ * private static class Store extends CacheStoreAdapter&lt;Integer, Integer&gt; {
+ *     &#64;CacheStoreSessionResource
+ *     private CacheStoreSession ses;
+ *
+ *     &#64;Override public void write(Cache.Entry&lt;? extends Integer, ? extends Integer&gt; entry) throws CacheWriterException {
+ *         // Get Hibernate session from the current store session.
+ *         Session hibSes = ses.attachment();
+ *
+ *         // Persist the value.
+ *         hibSes.persist(entry.getValue());
+ *     }
+ * }
+ * </pre>
+ * Hibernate session will be automatically created by the listener
+ * at the start of the session and closed when it ends.
+ * <p>
+ * {@link CacheHibernateStoreSessionListener} requires that either
+ * {@link #setSessionFactory(SessionFactory)} session factory}
+ * or {@link #setHibernateConfigurationPath(String) Hibernate configuration file}
+ * is provided. If non of them is set, exception is thrown. Is both are provided,
+ * session factory will be used.
+ */
+public class CacheHibernateStoreSessionListener implements CacheStoreSessionListener, LifecycleAware {
+    /** Hibernate session factory. */
+    private SessionFactory sesFactory;
+
+    /** Hibernate configuration file path. */
+    private String hibernateCfgPath;
+
+    /** Logger. */
+    @LoggerResource
+    private IgniteLogger log;
+
+    /** Whether to close session on stop. */
+    private boolean closeSesOnStop;
+
+    /**
+     * Sets Hibernate session factory.
+     * <p>
+     * Either session factory or configuration file is required.
+     * If none is provided, exception will be thrown on startup.
+     *
+     * @param sesFactory Session factory.
+     */
+    public void setSessionFactory(SessionFactory sesFactory) {
+        this.sesFactory = sesFactory;
+    }
+
+    /**
+     * Gets Hibernate session factory.
+     *
+     * @return Session factory.
+     */
+    public SessionFactory getSessionFactory() {
+        return sesFactory;
+    }
+
+    /**
+     * Sets hibernate configuration path.
+     * <p>
+     * Either session factory or configuration file is required.
+     * If none is provided, exception will be thrown on startup.
+     *
+     * @param hibernateCfgPath Hibernate configuration path.
+     */
+    public void setHibernateConfigurationPath(String hibernateCfgPath) {
+        this.hibernateCfgPath = hibernateCfgPath;
+    }
+
+    /**
+     * Gets hibernate configuration path.
+     *
+     * @return Hibernate configuration path.
+     */
+    public String getHibernateConfigurationPath() {
+        return hibernateCfgPath;
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("deprecation")
+    @Override public void start() throws IgniteException {
+        if (sesFactory == null && F.isEmpty(hibernateCfgPath))
+            throw new IgniteException("Either session factory or Hibernate configuration file is required by " +
+                getClass().getSimpleName() + '.');
+
+        if (!F.isEmpty(hibernateCfgPath)) {
+            if (sesFactory == null) {
+                try {
+                    URL url = new URL(hibernateCfgPath);
+
+                    sesFactory = new Configuration().configure(url).buildSessionFactory();
+                }
+                catch (MalformedURLException ignored) {
+                    // No-op.
+                }
+
+                if (sesFactory == null) {
+                    File cfgFile = new File(hibernateCfgPath);
+
+                    if (cfgFile.exists())
+                        sesFactory = new Configuration().configure(cfgFile).buildSessionFactory();
+                }
+
+                if (sesFactory == null)
+                    sesFactory = new Configuration().configure(hibernateCfgPath).buildSessionFactory();
+
+                if (sesFactory == null)
+                    throw new IgniteException("Failed to resolve Hibernate configuration file: " + hibernateCfgPath);
+
+                closeSesOnStop = true;
+            }
+            else
+                U.warn(log, "Hibernate configuration file configured in " + getClass().getSimpleName() +
+                    " will be ignored (session factory is already set).");
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void stop() throws IgniteException {
+        if (closeSesOnStop && sesFactory != null && !sesFactory.isClosed())
+            sesFactory.close();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onSessionStart(CacheStoreSession ses) {
+        if (ses.attachment() == null) {
+            try {
+                Session hibSes = sesFactory.openSession();
+
+                ses.attach(hibSes);
+
+                if (ses.isWithinTransaction())
+                    hibSes.beginTransaction();
+            }
+            catch (HibernateException e) {
+                throw new CacheWriterException("Failed to start store session [tx=" + ses.transaction() + ']', e);
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onSessionEnd(CacheStoreSession ses, boolean commit) {
+        Session hibSes = ses.attach(null);
+
+        if (hibSes != null) {
+            try {
+                Transaction tx = hibSes.getTransaction();
+
+                if (commit) {
+                    if (hibSes.isDirty())
+                        hibSes.flush();
+
+                    if (tx.getStatus() == TransactionStatus.ACTIVE)
+                        tx.commit();
+                }
+                else if (tx.getStatus().canRollback())
+                    tx.rollback();
+            }
+            catch (HibernateException e) {
+                throw new CacheWriterException("Failed to end store session [tx=" + ses.transaction() + ']', e);
+            }
+            finally {
+                hibSes.close();
+            }
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/package-info.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/package-info.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/package-info.java
new file mode 100644
index 0000000..891d99a
--- /dev/null
+++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/store/hibernate/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * <!-- Package description. -->
+ * Contains reference Hibernate-based cache store implementation.
+ */
+package org.apache.ignite.cache.store.hibernate;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/test/config/factory-cache.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/test/config/factory-cache.xml b/modules/hibernate-5.1/src/test/config/factory-cache.xml
new file mode 100644
index 0000000..a251846
--- /dev/null
+++ b/modules/hibernate-5.1/src/test/config/factory-cache.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+        http://www.springframework.org/schema/beans
+        http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+    <bean id="simpleSessionFactory"
+          class="org.apache.ignite.cache.store.hibernate.CacheHibernateStoreFactorySelfTest$DummySessionFactoryExt"/>
+
+    <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+        <property name="cacheConfiguration">
+            <list>
+                <bean class="org.apache.ignite.configuration.CacheConfiguration">
+                    <property name="name" value="test"/>
+                    <property name="atomicityMode" value="ATOMIC"/>
+                    <property name="backups" value="1"/>
+                    <property name="cacheStoreFactory">
+                        <bean class="org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory">
+                            <property name="sessionFactoryBean" value = "simpleSessionFactory"/>
+                        </bean>
+                    </property>
+                </bean>
+            </list>
+        </property>
+
+        <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
+        <property name="discoverySpi">
+            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+                <property name="ipFinder">
+                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
+                        <property name="addresses">
+                            <list>
+                                <value>127.0.0.1:47500..47509</value>
+                            </list>
+                        </property>
+                    </bean>
+                </property>
+            </bean>
+        </property>
+    </bean>
+</beans>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/test/config/factory-cache1.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/test/config/factory-cache1.xml b/modules/hibernate-5.1/src/test/config/factory-cache1.xml
new file mode 100644
index 0000000..7a53b1f
--- /dev/null
+++ b/modules/hibernate-5.1/src/test/config/factory-cache1.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+        http://www.springframework.org/schema/beans
+        http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+    <bean id="simpleSessionFactory1"
+          class="org.apache.ignite.cache.store.hibernate.CacheHibernateStoreFactorySelfTest$DummySessionFactory"/>
+
+    <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+        <property name="igniteInstanceName" value="ignite1"/>
+
+        <property name="cacheConfiguration">
+            <list>
+                <bean class="org.apache.ignite.configuration.CacheConfiguration">
+                    <property name="name" value="test"/>
+                    <property name="atomicityMode" value="ATOMIC"/>
+                    <property name="backups" value="1"/>
+                    <property name="cacheStoreFactory">
+                        <bean class="org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory">
+                            <property name="sessionFactoryBean" value = "simpleSessionFactory1"/>
+                        </bean>
+                    </property>
+                </bean>
+            </list>
+        </property>
+
+        <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
+        <property name="discoverySpi">
+            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+                <property name="ipFinder">
+                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
+                        <property name="addresses">
+                            <list>
+                                <value>127.0.0.1:47500..47509</value>
+                            </list>
+                        </property>
+                    </bean>
+                </property>
+            </bean>
+        </property>
+    </bean>
+</beans>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/test/config/factory-incorrect-store-cache.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/test/config/factory-incorrect-store-cache.xml b/modules/hibernate-5.1/src/test/config/factory-incorrect-store-cache.xml
new file mode 100644
index 0000000..459930c
--- /dev/null
+++ b/modules/hibernate-5.1/src/test/config/factory-incorrect-store-cache.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+        http://www.springframework.org/schema/beans
+        http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+    <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+        <property name="cacheConfiguration">
+            <list>
+                <bean class="org.apache.ignite.configuration.CacheConfiguration">
+                    <property name="name" value="test"/>
+                    <property name="atomicityMode" value="ATOMIC"/>
+                    <property name="backups" value="1"/>
+                    <property name="cacheStoreFactory">
+                        <bean class="org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory">
+                            <property name="sessionFactoryBean" value = "simpleSessionFactory1"/>
+                        </bean>
+                    </property>
+                </bean>
+            </list>
+        </property>
+
+        <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
+        <property name="discoverySpi">
+            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+                <property name="ipFinder">
+                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
+                        <property name="addresses">
+                            <list>
+                                <value>127.0.0.1:47500..47509</value>
+                            </list>
+                        </property>
+                    </bean>
+                </property>
+            </bean>
+        </property>
+    </bean>
+</beans>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheConfigurationSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheConfigurationSelfTest.java b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheConfigurationSelfTest.java
new file mode 100644
index 0000000..0363c41
--- /dev/null
+++ b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheConfigurationSelfTest.java
@@ -0,0 +1,407 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import javax.cache.Cache;
+import javax.persistence.Cacheable;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
+import org.hibernate.cache.spi.access.AccessType;
+import org.hibernate.cfg.Configuration;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.DFLT_CACHE_NAME_PROPERTY;
+import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.REGION_CACHE_PROPERTY;
+import static org.hibernate.cfg.AvailableSettings.CACHE_REGION_FACTORY;
+import static org.hibernate.cfg.AvailableSettings.GENERATE_STATISTICS;
+import static org.hibernate.cfg.AvailableSettings.HBM2DDL_AUTO;
+import static org.hibernate.cfg.AvailableSettings.RELEASE_CONNECTIONS;
+import static org.hibernate.cfg.AvailableSettings.USE_QUERY_CACHE;
+import static org.hibernate.cfg.AvailableSettings.USE_SECOND_LEVEL_CACHE;
+
+/**
+ * Tests Hibernate L2 cache configuration.
+ */
+public class HibernateL2CacheConfigurationSelfTest extends GridCommonAbstractTest {
+    /** */
+    public static final String ENTITY1_NAME = Entity1.class.getName();
+
+    /** */
+    public static final String ENTITY2_NAME = Entity2.class.getName();
+
+    /** */
+    public static final String ENTITY3_NAME = Entity3.class.getName();
+
+    /** */
+    public static final String ENTITY4_NAME = Entity4.class.getName();
+
+    /** */
+    public static final String TIMESTAMP_CACHE = "org.hibernate.cache.spi.UpdateTimestampsCache";
+
+    /** */
+    public static final String QUERY_CACHE = "org.hibernate.cache.internal.StandardQueryCache";
+
+    /** */
+    public static final String CONNECTION_URL = "jdbc:h2:mem:example;DB_CLOSE_DELAY=-1";
+
+    /** If {@code true} then sets default cache in configuration. */
+    private boolean dfltCache;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrid(0);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        for (IgniteCacheProxy<?, ?> cache : ((IgniteKernal)grid(0)).caches())
+            cache.clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
+
+        discoSpi.setIpFinder(new TcpDiscoveryVmIpFinder(true));
+
+        cfg.setDiscoverySpi(discoSpi);
+
+        cfg.setCacheConfiguration(cacheConfiguration(ENTITY3_NAME), cacheConfiguration(ENTITY4_NAME),
+            cacheConfiguration("cache1"), cacheConfiguration("cache2"), cacheConfiguration("cache3"),
+            cacheConfiguration(TIMESTAMP_CACHE), cacheConfiguration(QUERY_CACHE));
+
+        return cfg;
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @return Cache configuration.
+     */
+    private CacheConfiguration cacheConfiguration(String cacheName) {
+        CacheConfiguration cfg = new CacheConfiguration();
+
+        cfg.setName(cacheName);
+
+        cfg.setCacheMode(PARTITIONED);
+
+        cfg.setAtomicityMode(ATOMIC);
+
+        return cfg;
+    }
+    /**
+     * @param igniteInstanceName Ignite instance name.
+     * @return Hibernate configuration.
+     */
+    protected Configuration hibernateConfiguration(String igniteInstanceName) {
+        Configuration cfg = new Configuration();
+
+        cfg.addAnnotatedClass(Entity1.class);
+        cfg.addAnnotatedClass(Entity2.class);
+        cfg.addAnnotatedClass(Entity3.class);
+        cfg.addAnnotatedClass(Entity4.class);
+
+        cfg.setProperty(HibernateAccessStrategyFactory.DFLT_ACCESS_TYPE_PROPERTY, AccessType.NONSTRICT_READ_WRITE.name());
+
+        cfg.setProperty(HBM2DDL_AUTO, "create");
+
+        cfg.setProperty(GENERATE_STATISTICS, "true");
+
+        cfg.setProperty(USE_SECOND_LEVEL_CACHE, "true");
+
+        cfg.setProperty(USE_QUERY_CACHE, "true");
+
+        cfg.setProperty(CACHE_REGION_FACTORY, HibernateRegionFactory.class.getName());
+
+        cfg.setProperty(RELEASE_CONNECTIONS, "on_close");
+
+        cfg.setProperty(HibernateAccessStrategyFactory.IGNITE_INSTANCE_NAME_PROPERTY, igniteInstanceName);
+
+        cfg.setProperty(REGION_CACHE_PROPERTY + ENTITY1_NAME, "cache1");
+        cfg.setProperty(REGION_CACHE_PROPERTY + ENTITY2_NAME, "cache2");
+        cfg.setProperty(REGION_CACHE_PROPERTY + TIMESTAMP_CACHE, TIMESTAMP_CACHE);
+        cfg.setProperty(REGION_CACHE_PROPERTY + QUERY_CACHE, QUERY_CACHE);
+
+        if (dfltCache)
+            cfg.setProperty(DFLT_CACHE_NAME_PROPERTY, "cache3");
+
+        return cfg;
+    }
+
+    /**
+     * Tests property {@link HibernateAccessStrategyFactory#REGION_CACHE_PROPERTY}.
+     */
+    public void testPerRegionCacheProperty() {
+        testCacheUsage(1, 1, 0, 1, 1);
+    }
+
+    /**
+     * Tests property {@link HibernateAccessStrategyFactory#DFLT_CACHE_NAME_PROPERTY}.
+     */
+    public void testDefaultCache() {
+        dfltCache = true;
+
+        testCacheUsage(1, 1, 2, 0, 0);
+    }
+
+    /**
+     * @param expCache1 Expected size of cache with name 'cache1'.
+     * @param expCache2 Expected size of cache with name 'cache2'.
+     * @param expCache3 Expected size of cache with name 'cache3'.
+     * @param expCacheE3 Expected size of cache with name {@link #ENTITY3_NAME}.
+     * @param expCacheE4 Expected size of cache with name {@link #ENTITY4_NAME}.
+     */
+    @SuppressWarnings("unchecked")
+    private void testCacheUsage(int expCache1, int expCache2, int expCache3, int expCacheE3, int expCacheE4) {
+        SessionFactory sesFactory = startHibernate(getTestIgniteInstanceName(0));
+
+        try {
+            Session ses = sesFactory.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                ses.save(new Entity1());
+                ses.save(new Entity2());
+                ses.save(new Entity3());
+                ses.save(new Entity4());
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            ses = sesFactory.openSession();
+
+            try {
+                List<Entity1> list1 = ses.createCriteria(ENTITY1_NAME).list();
+
+                assertEquals(1, list1.size());
+
+                for (Entity1 e : list1) {
+                    ses.load(ENTITY1_NAME, e.getId());
+                    assertNotNull(e.getId());
+                }
+
+                List<Entity2> list2 = ses.createCriteria(ENTITY2_NAME).list();
+
+                assertEquals(1, list2.size());
+
+                for (Entity2 e : list2)
+                    assertNotNull(e.getId());
+
+                List<Entity3> list3 = ses.createCriteria(ENTITY3_NAME).list();
+
+                assertEquals(1, list3.size());
+
+                for (Entity3 e : list3)
+                    assertNotNull(e.getId());
+
+                List<Entity4> list4 = ses.createCriteria(ENTITY4_NAME).list();
+
+                assertEquals(1, list4.size());
+
+                for (Entity4 e : list4)
+                    assertNotNull(e.getId());
+            }
+            finally {
+                ses.close();
+            }
+
+            IgniteCache<Object, Object> cache1 = grid(0).cache("cache1");
+            IgniteCache<Object, Object> cache2 = grid(0).cache("cache2");
+            IgniteCache<Object, Object> cache3 = grid(0).cache("cache3");
+            IgniteCache<Object, Object> cacheE3 = grid(0).cache(ENTITY3_NAME);
+            IgniteCache<Object, Object> cacheE4 = grid(0).cache(ENTITY4_NAME);
+
+            assertEquals("Unexpected entries: " + toSet(cache1.iterator()), expCache1, cache1.size());
+            assertEquals("Unexpected entries: " + toSet(cache2.iterator()), expCache2, cache2.size());
+            assertEquals("Unexpected entries: " + toSet(cache3.iterator()), expCache3, cache3.size());
+            assertEquals("Unexpected entries: " + toSet(cacheE3.iterator()), expCacheE3, cacheE3.size());
+            assertEquals("Unexpected entries: " + toSet(cacheE4.iterator()), expCacheE4, cacheE4.size());
+        }
+        finally {
+            sesFactory.close();
+        }
+    }
+
+    /**
+     *
+     */
+    private <K, V> Set<Cache.Entry<K, V>> toSet(Iterator<Cache.Entry<K, V>> iter){
+        Set<Cache.Entry<K, V>> set = new HashSet<>();
+
+        while (iter.hasNext())
+            set.add(iter.next());
+
+        return set;
+    }
+
+    /**
+     * @param igniteInstanceName Name of the grid providing caches.
+     * @return Session factory.
+     */
+    private SessionFactory startHibernate(String igniteInstanceName) {
+        Configuration cfg = hibernateConfiguration(igniteInstanceName);
+
+        StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
+
+        builder.applySetting("hibernate.connection.url", CONNECTION_URL);
+        builder.applySetting("hibernate.show_sql", false);
+        builder.applySettings(cfg.getProperties());
+
+        return cfg.buildSessionFactory(builder.build());
+    }
+
+    /**
+     * Test Hibernate entity1.
+     */
+    @javax.persistence.Entity
+    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
+    @Cacheable
+    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+    public static class Entity1 {
+        /** */
+        private int id;
+
+        /**
+         * @return ID.
+         */
+        @Id
+        @GeneratedValue
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(int id) {
+            this.id = id;
+        }
+    }
+
+    /**
+     * Test Hibernate entity2.
+     */
+    @javax.persistence.Entity
+    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
+    @Cacheable
+    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+    public static class Entity2 {
+        /** */
+        private int id;
+
+        /**
+         * @return ID.
+         */
+        @Id
+        @GeneratedValue
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(int id) {
+            this.id = id;
+        }
+    }
+
+    /**
+     * Test Hibernate entity3.
+     */
+    @javax.persistence.Entity
+    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
+    @Cacheable
+    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+    public static class Entity3 {
+        /** */
+        private int id;
+
+        /**
+         * @return ID.
+         */
+        @Id
+        @GeneratedValue
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(int id) {
+            this.id = id;
+        }
+    }
+
+    /**
+     * Test Hibernate entity4.
+     */
+    @javax.persistence.Entity
+    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
+    @Cacheable
+    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+    public static class Entity4 {
+        /** */
+        private int id;
+
+        /**
+         * @return ID.
+         */
+        @Id
+        @GeneratedValue
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(int id) {
+            this.id = id;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheMultiJvmTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheMultiJvmTest.java b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheMultiJvmTest.java
new file mode 100644
index 0000000..57a3f71
--- /dev/null
+++ b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheMultiJvmTest.java
@@ -0,0 +1,429 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import java.util.Map;
+import javax.persistence.Cacheable;
+import javax.persistence.Id;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCompute;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.resources.IgniteInstanceResource;
+import org.apache.ignite.resources.LoggerResource;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+import org.hibernate.boot.MetadataSources;
+import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
+
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.DFLT_CACHE_NAME_PROPERTY;
+import static org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest.CONNECTION_URL;
+import static org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest.hibernateProperties;
+import static org.hibernate.cache.spi.access.AccessType.NONSTRICT_READ_WRITE;
+
+/**
+ *
+ */
+public class HibernateL2CacheMultiJvmTest extends GridCommonAbstractTest {
+    /** */
+    private static final String CACHE_NAME = "hibernateCache";
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        if (!getTestIgniteInstanceName(0).equals(igniteInstanceName))
+            cfg.setClientMode(true);
+
+        CacheConfiguration ccfg = new CacheConfiguration();
+
+        ccfg.setName(CACHE_NAME);
+        ccfg.setWriteSynchronizationMode(FULL_SYNC);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        cfg.setPeerClassLoadingEnabled(false);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean isMultiJvm() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        startGrid(0);
+
+        startGrid(1);
+        startGrid(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+
+        super.afterTestsStopped();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testL2Cache() throws Exception {
+        Ignite srv = ignite(0);
+
+        {
+            IgniteCompute client1Compute =
+                srv.compute(srv.cluster().forNodeId(ignite(1).cluster().localNode().id()));
+
+            client1Compute.run(new HibernateInsertRunnable());
+        }
+
+        {
+            IgniteCompute client2Compute =
+                srv.compute(srv.cluster().forNodeId(ignite(2).cluster().localNode().id()));
+
+            client2Compute.run(new HibernateLoadRunnable());
+        }
+
+        {
+            IgniteCompute srvCompute = srv.compute(srv.cluster().forLocal());
+
+            srvCompute.run(new HibernateLoadRunnable());
+        }
+    }
+
+    /**
+     *
+     */
+    private static class HibernateInsertRunnable extends HibernateBaseRunnable {
+        /** {@inheritDoc} */
+        @Override public void run() {
+            SessionFactory sesFactory = startHibernate(ignite.name());
+
+            Session ses = sesFactory.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                for (int i = 0; i < 1; i++) {
+                    {
+                        Entity1 e = new Entity1();
+                        e.setId(i);
+                        e.setName("name-" + i);
+
+                        ses.save(e);
+                    }
+
+                    {
+                        Entity2 e = new Entity2();
+                        e.setId(String.valueOf(i));
+                        e.setName("name-" + i);
+
+                        ses.save(e);
+                    }
+
+                    {
+                        Entity3 e = new Entity3();
+                        e.setId(i);
+                        e.setName("name-" + i);
+
+                        ses.save(e);
+                    }
+                }
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+        }
+    }
+
+    /**
+     *
+     */
+    private static class HibernateLoadRunnable extends HibernateBaseRunnable {
+        /** {@inheritDoc} */
+        @Override public void run() {
+            SessionFactory sesFactory = startHibernate(ignite.name());
+
+            Session ses = sesFactory.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                for (int i = 0; i < 1; i++) {
+                    {
+                        Entity1 e = (Entity1)ses.load(Entity1.class, i);
+
+                        log.info("Found: " + e.getName());
+                    }
+                    {
+                        Entity2 e = (Entity2)ses.load(Entity2.class, String.valueOf(i));
+
+                        log.info("Found: " + e.getName());
+                    }
+                    {
+                        Entity3 e = (Entity3)ses.load(Entity3.class, (double)i);
+
+                        log.info("Found: " + e.getName());
+                    }
+                }
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+        }
+    }
+
+    /**
+     *
+     */
+    private abstract static class HibernateBaseRunnable implements IgniteRunnable {
+        /** */
+        @IgniteInstanceResource
+        protected Ignite ignite;
+
+        /** */
+        @LoggerResource
+        IgniteLogger log;
+
+        /**
+         * @param nodeName Name of the grid providing caches.
+         * @return Session factory.
+         */
+        SessionFactory startHibernate(String nodeName) {
+            log.info("Start hibernate on node: " + nodeName);
+
+            StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
+
+            for (Map.Entry<String, String> e : hibernateProperties(nodeName, NONSTRICT_READ_WRITE.name()).entrySet())
+                builder.applySetting(e.getKey(), e.getValue());
+
+            builder.applySetting("hibernate.connection.url", CONNECTION_URL);
+            builder.applySetting(DFLT_CACHE_NAME_PROPERTY, CACHE_NAME);
+
+            MetadataSources metadataSources = new MetadataSources(builder.build());
+
+            metadataSources.addAnnotatedClass(Entity1.class);
+            metadataSources.addAnnotatedClass(Entity2.class);
+            metadataSources.addAnnotatedClass(Entity3.class);
+
+            return metadataSources.buildMetadata().buildSessionFactory();
+        }
+    }
+
+    /**
+     * Test Hibernate entity1.
+     */
+    @javax.persistence.Entity
+    @Cacheable
+    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+    public static class Entity1 {
+        /** */
+        @Id
+        private int id;
+
+        /** */
+        private String name;
+
+        /**
+         * @return ID.
+         */
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(int id) {
+            this.id = id;
+        }
+
+        /**
+         * @return Name.
+         */
+        public String getName() {
+            return name;
+        }
+
+        /**
+         * @param name Name.
+         */
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            Entity1 entity1 = (Entity1)o;
+
+            return id == entity1.id;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return id;
+        }
+    }
+
+    /**
+     * Test Hibernate entity1.
+     */
+    @javax.persistence.Entity
+    @Cacheable
+    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+    public static class Entity2 {
+        /** */
+        @Id
+        private String id;
+
+        /** */
+        private String name;
+
+        /**
+         * @return ID.
+         */
+        public String getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(String id) {
+            this.id = id;
+        }
+
+        /**
+         * @return Name.
+         */
+        public String getName() {
+            return name;
+        }
+
+        /**
+         * @param name Name.
+         */
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            Entity2 entity2 = (Entity2)o;
+
+            return id.equals(entity2.id);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return id.hashCode();
+        }
+    }
+
+    /**
+     * Test Hibernate entity1.
+     */
+    @javax.persistence.Entity
+    @Cacheable
+    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+    public static class Entity3 {
+        /** */
+        @Id
+        private double id;
+
+        /** */
+        private String name;
+
+        /**
+         * @return ID.
+         */
+        public double getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(double id) {
+            this.id = id;
+        }
+
+        /**
+         * @return Name.
+         */
+        public String getName() {
+            return name;
+        }
+
+        /**
+         * @param name Name.
+         */
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            Entity3 entity3 = (Entity3)o;
+
+            return Double.compare(entity3.id, id) == 0;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            long temp = Double.doubleToLongBits(id);
+            return (int)(temp ^ (temp >>> 32));
+        }
+    }
+}


[04/16] ignite git commit: ignite-1794 Refactored hibernate modules, switched to hibernate 5.1

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java
deleted file mode 100644
index 1842a63..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.apache.ignite.Ignite;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.internal.DefaultCacheKeysFactory;
-import org.hibernate.cache.spi.CacheDataDescription;
-import org.hibernate.cache.spi.EntityRegion;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
-import org.hibernate.cache.spi.access.SoftLock;
-import org.hibernate.engine.spi.SessionFactoryImplementor;
-import org.hibernate.engine.spi.SharedSessionContractImplementor;
-import org.hibernate.persister.entity.EntityPersister;
-
-/**
- * Implementation of {@link EntityRegion}. This region is used to store entity data.
- * <p>
- * L2 cache for entity can be enabled in the Hibernate configuration file:
- * <pre name="code" class="xml">
- * &lt;hibernate-configuration&gt;
- *     &lt;!-- Enable L2 cache. --&gt;
- *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
- *
- *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
- *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
- *
- *     &lt;!-- Specify entity. --&gt;
- *     &lt;mapping class="com.example.Entity"/&gt;
- *
- *     &lt;!-- Enable L2 cache with nonstrict-read-write access strategy for entity. --&gt;
- *     &lt;class-cache class="com.example.Entity" usage="nonstrict-read-write"/&gt;
- * &lt;/hibernate-configuration&gt;
- * </pre>
- * Also cache for entity can be enabled using annotations:
- * <pre name="code" class="java">
- * &#064;javax.persistence.Entity
- * &#064;javax.persistence.Cacheable
- * &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
- * public class Entity { ... }
- * </pre>
- */
-public class HibernateEntityRegion extends HibernateTransactionalDataRegion implements EntityRegion {
-    /**
-     * @param factory Region factory.
-     * @param name Region name.
-     * @param ignite Grid.
-     * @param cache Region cache,
-     * @param dataDesc Region data description.
-     */
-    public HibernateEntityRegion(HibernateRegionFactory factory, String name, Ignite ignite,
-        HibernateCacheProxy cache, CacheDataDescription dataDesc) {
-        super(factory, name, ignite, cache, dataDesc);
-    }
-
-    /** {@inheritDoc} */
-    @Override public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
-        return new AccessStrategy(createAccessStrategy(accessType));
-    }
-
-    /**
-     * Entity region access strategy.
-     */
-    private class AccessStrategy extends HibernateAbstractRegionAccessStrategy
-        implements EntityRegionAccessStrategy {
-        /**
-         * @param stgy Access strategy implementation.
-         */
-        private AccessStrategy(HibernateAccessStrategyAdapter stgy) {
-            super(stgy);
-        }
-
-        /** {@inheritDoc} */
-        @Override public Object generateCacheKey(Object id,
-            EntityPersister persister,
-            SessionFactoryImplementor factory,
-            String tenantIdentifier) {
-            return HibernateKeyWrapper.staticCreateEntityKey(id, persister, tenantIdentifier);
-        }
-
-        /** {@inheritDoc} */
-        @Override public Object getCacheKeyId(Object cacheKey) {
-            return ((HibernateKeyWrapper)cacheKey).id();
-        }
-
-        /** {@inheritDoc} */
-        @Override public EntityRegion getRegion() {
-            return HibernateEntityRegion.this;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean insert(SharedSessionContractImplementor ses, Object key, Object val, Object ver) throws CacheException {
-            return stgy.insert(key, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean afterInsert(SharedSessionContractImplementor ses, Object key, Object val, Object ver) throws CacheException {
-            return stgy.afterInsert(key, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean update(SharedSessionContractImplementor ses, Object key, Object val, Object currVer, Object previousVer)
-            throws CacheException {
-            return stgy.update(key, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean afterUpdate(SharedSessionContractImplementor ses, Object key, Object val, Object currVer, Object previousVer, SoftLock lock)
-            throws CacheException {
-            return stgy.afterUpdate(key, val, lock);
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateGeneralDataRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateGeneralDataRegion.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateGeneralDataRegion.java
deleted file mode 100644
index 2b34804..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateGeneralDataRegion.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCheckedException;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.GeneralDataRegion;
-import org.hibernate.cache.spi.QueryResultsRegion;
-import org.hibernate.cache.spi.TimestampsRegion;
-import org.hibernate.engine.spi.SharedSessionContractImplementor;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Implementation of {@link GeneralDataRegion}. This interface defines common contract for {@link QueryResultsRegion}
- * and {@link TimestampsRegion}.
- */
-public class HibernateGeneralDataRegion extends HibernateRegion implements GeneralDataRegion {
-    /**
-     * @param factory Region factory.
-     * @param name Region name.
-     * @param ignite Grid.
-     * @param cache Region cache.
-     */
-    public HibernateGeneralDataRegion(HibernateRegionFactory factory, String name,
-        Ignite ignite, HibernateCacheProxy cache) {
-        super(factory, name, ignite, cache);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object get(SharedSessionContractImplementor ses, Object key) throws CacheException {
-        try {
-            return cache.get(key);
-        } catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void put(SharedSessionContractImplementor ses, Object key, Object val) throws CacheException {
-        try {
-            cache.put(key, val);
-        } catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void evict(Object key) throws CacheException {
-        HibernateAccessStrategyAdapter.evict(ignite, cache, key);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void evictAll() throws CacheException {
-        HibernateAccessStrategyAdapter.evictAll(cache);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyTransformer.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyTransformer.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyTransformer.java
deleted file mode 100644
index ecad0b6..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyTransformer.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-/**
- * An interface for transforming hibernate keys to Ignite keys.
- */
-public interface HibernateKeyTransformer {
-    /**
-     * @param key Hibernate key.
-     */
-    public Object transform(Object key);
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
deleted file mode 100644
index ff52124..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.hibernate.cache.internal.DefaultCacheKeysFactory;
-import org.hibernate.engine.spi.SessionFactoryImplementor;
-import org.hibernate.persister.collection.CollectionPersister;
-import org.hibernate.persister.entity.EntityPersister;
-
-/**
- * Hibernate cache key wrapper.
- */
-public class HibernateKeyWrapper {
-    /** Key. */
-    private final Object key;
-
-    /** Entry. */
-    private final String entry;
-
-    /** */
-    private final String tenantId;
-
-    /**
-     * @param key Key.
-     * @param entry Entry.
-     * @param tenantId Tenant ID.
-     */
-    HibernateKeyWrapper(Object key, String entry, String tenantId) {
-        this.key = key;
-        this.entry = entry;
-        this.tenantId = tenantId;
-    }
-
-    /**
-     * @return ID.
-     */
-    Object id() {
-        return key;
-    }
-
-    /**
-     * @param id ID.
-     * @param persister Persister.
-     * @param tenantIdentifier Tenant ID.
-     * @return Cache key.
-     * @see DefaultCacheKeysFactory#staticCreateCollectionKey(Object, CollectionPersister, SessionFactoryImplementor, String)
-     */
-    static Object staticCreateCollectionKey(Object id,
-        CollectionPersister persister,
-        String tenantIdentifier) {
-        return new HibernateKeyWrapper(id, persister.getRole(), tenantIdentifier);
-    }
-
-    /**
-     * @param id ID.
-     * @param persister Persister.
-     * @param tenantIdentifier Tenant ID.
-     * @return Cache key.
-     * @see DefaultCacheKeysFactory#staticCreateEntityKey(Object, EntityPersister, SessionFactoryImplementor, String)
-     */
-    public static Object staticCreateEntityKey(Object id, EntityPersister persister, String tenantIdentifier) {
-        return new HibernateKeyWrapper(id, persister.getRootEntityName(), tenantIdentifier);
-    }
-
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o) return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        HibernateKeyWrapper that = (HibernateKeyWrapper) o;
-
-        return (key != null ? key.equals(that.key) : that.key == null) &&
-            (entry != null ? entry.equals(that.entry) : that.entry == null) &&
-            (tenantId != null ? tenantId.equals(that.tenantId) : that.tenantId == null);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = key != null ? key.hashCode() : 0;
-        res = 31 * res + (entry != null ? entry.hashCode() : 0);
-        res = 31 * res + (tenantId != null ? tenantId.hashCode() : 0);
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(HibernateKeyWrapper.class, this);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateNaturalIdRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateNaturalIdRegion.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateNaturalIdRegion.java
deleted file mode 100644
index 73ed23a..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateNaturalIdRegion.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.apache.ignite.Ignite;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.internal.DefaultCacheKeysFactory;
-import org.hibernate.cache.spi.CacheDataDescription;
-import org.hibernate.cache.spi.NaturalIdRegion;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy;
-import org.hibernate.cache.spi.access.SoftLock;
-import org.hibernate.engine.spi.SharedSessionContractImplementor;
-import org.hibernate.persister.entity.EntityPersister;
-
-/**
- * Implementation of {@link NaturalIdRegion}. This region is used to store naturalId data.
- * <p>
- * L2 cache for entity naturalId and target cache region can be set using annotations:
- * <pre name="code" class="java">
- * &#064;javax.persistence.Entity
- * &#064;javax.persistence.Cacheable
- * &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
- * &#064;org.hibernate.annotations.NaturalIdCache
- * public class Entity {
- *     &#064;org.hibernate.annotations.NaturalId
- *     private String entityCode;
- *
- *     ...
- * }
- * </pre>
- */
-public class HibernateNaturalIdRegion extends HibernateTransactionalDataRegion implements NaturalIdRegion {
-    /**
-     * @param factory Region factory.
-     * @param name Region name.
-     * @param ignite Grid.
-     * @param cache Region cache,
-     * @param dataDesc Region data description.
-     */
-    public HibernateNaturalIdRegion(HibernateRegionFactory factory, String name,
-        Ignite ignite, HibernateCacheProxy cache, CacheDataDescription dataDesc) {
-        super(factory, name, ignite, cache, dataDesc);
-    }
-
-    /** {@inheritDoc} */
-    @Override public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
-        return new AccessStrategy(createAccessStrategy(accessType));
-    }
-
-    /**
-     * NaturalId region access strategy.
-     */
-    private class AccessStrategy extends HibernateAbstractRegionAccessStrategy implements
-        NaturalIdRegionAccessStrategy {
-        /**
-         * @param stgy Access strategy implementation.
-         */
-        private AccessStrategy(HibernateAccessStrategyAdapter stgy) {
-            super(stgy);
-        }
-
-        /** {@inheritDoc} */
-        @Override public Object generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SharedSessionContractImplementor ses) {
-            return DefaultCacheKeysFactory.staticCreateNaturalIdKey(naturalIdValues, persister, ses);
-        }
-
-        /** {@inheritDoc} */
-        @Override public Object[] getNaturalIdValues(Object cacheKey) {
-            return DefaultCacheKeysFactory.staticGetNaturalIdValues(cacheKey);
-        }
-
-        /** {@inheritDoc} */
-        @Override public NaturalIdRegion getRegion() {
-            return HibernateNaturalIdRegion.this;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean insert(SharedSessionContractImplementor ses, Object key, Object val) throws CacheException {
-            return stgy.insert(key, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean afterInsert(SharedSessionContractImplementor ses, Object key, Object val) throws CacheException {
-            return stgy.afterInsert(key, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean update(SharedSessionContractImplementor ses, Object key, Object val) throws CacheException {
-            return stgy.update(key, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean afterUpdate(SharedSessionContractImplementor ses, Object key, Object val, SoftLock lock) throws CacheException {
-            return stgy.afterUpdate(key, val, lock);
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateNonStrictAccessStrategy.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateNonStrictAccessStrategy.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateNonStrictAccessStrategy.java
deleted file mode 100644
index a36d7e7..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateNonStrictAccessStrategy.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import java.util.Map;
-import java.util.Set;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.util.GridLeanMap;
-import org.apache.ignite.internal.util.GridLeanSet;
-import org.apache.ignite.internal.util.typedef.F;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cache.spi.access.SoftLock;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Implementation of {@link AccessType#NONSTRICT_READ_WRITE} cache access strategy.
- * <p>
- * Configuration of L2 cache and per-entity cache access strategy can be set in the
- * Hibernate configuration file:
- * <pre name="code" class="xml">
- * &lt;hibernate-configuration&gt;
- *     &lt;!-- Enable L2 cache. --&gt;
- *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
- *
- *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
- *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
- *
- *     &lt;!-- Specify entity. --&gt;
- *     &lt;mapping class="com.example.Entity"/&gt;
- *
- *     &lt;!-- Enable L2 cache with nonstrict-read-write access strategy for entity. --&gt;
- *     &lt;class-cache class="com.example.Entity" usage="nonstrict-read-write"/&gt;
- * &lt;/hibernate-configuration&gt;
- * </pre>
- * Also cache access strategy can be set using annotations:
- * <pre name="code" class="java">
- * &#064;javax.persistence.Entity
- * &#064;javax.persistence.Cacheable
- * &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
- * public class Entity { ... }
- * </pre>
- */
-public class HibernateNonStrictAccessStrategy extends HibernateAccessStrategyAdapter {
-    /** */
-    private final ThreadLocal<WriteContext> writeCtx;
-
-    /**
-     * @param ignite Grid.
-     * @param cache Cache.
-     * @param writeCtx Thread local instance used to track updates done during one Hibernate transaction.
-     */
-    protected HibernateNonStrictAccessStrategy(Ignite ignite, HibernateCacheProxy cache, ThreadLocal writeCtx) {
-        super(ignite, cache);
-
-        this.writeCtx = (ThreadLocal<WriteContext>)writeCtx;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override protected SoftLock lock(Object key) throws CacheException {
-        WriteContext ctx = writeCtx.get();
-
-        if (ctx == null)
-            writeCtx.set(ctx = new WriteContext());
-
-        ctx.locked(key);
-
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void unlock(Object key, SoftLock lock) throws CacheException {
-        try {
-            WriteContext ctx = writeCtx.get();
-
-            if (ctx != null && ctx.unlocked(key)) {
-                writeCtx.remove();
-
-                ctx.updateCache(cache);
-            }
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean update(Object key, Object val) throws CacheException {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean afterUpdate(Object key, Object val, SoftLock lock) throws CacheException {
-        WriteContext ctx = writeCtx.get();
-
-        if (ctx != null) {
-            ctx.updated(key, val);
-
-            unlock(key, lock);
-
-            return true;
-        }
-
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean insert(Object key, Object val) throws CacheException {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean afterInsert(Object key, Object val) throws CacheException {
-        try {
-            cache.put(key, val);
-
-            return true;
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void remove(Object key) throws CacheException {
-        WriteContext ctx = writeCtx.get();
-
-        if (ctx != null)
-            ctx.removed(key);
-    }
-
-    /**
-     * Information about updates done during single database transaction.
-     */
-    @SuppressWarnings("TypeMayBeWeakened")
-    private static class WriteContext {
-        /** */
-        private Map<Object, Object> updates;
-
-        /** */
-        private Set<Object> rmvs;
-
-        /** */
-        private Set<Object> locked = new GridLeanSet<>();
-
-        /**
-         * Marks key as locked.
-         *
-         * @param key Key.
-         */
-        void locked(Object key) {
-            locked.add(key);
-        }
-
-        /**
-         * Marks key as unlocked.
-         *
-         * @param key Key.
-         * @return {@code True} if last locked key was unlocked.
-         */
-        boolean unlocked(Object key) {
-            locked.remove(key);
-
-            return locked.isEmpty();
-        }
-
-        /**
-         * Marks key as updated.
-         *
-         * @param key Key.
-         * @param val Value.
-         */
-        void updated(Object key, Object val) {
-            if (updates == null)
-                updates = new GridLeanMap<>();
-
-            updates.put(key, val);
-        }
-
-        /**
-         * Marks key as removed.
-         *
-         * @param key Key.
-         */
-        void removed(Object key) {
-            if (rmvs == null)
-                rmvs = new GridLeanSet<>();
-
-            rmvs.add(key);
-        }
-
-        /**
-         * Updates cache.
-         *
-         * @param cache Cache.
-         * @throws IgniteCheckedException If failed.
-         */
-        void updateCache(HibernateCacheProxy cache) throws IgniteCheckedException {
-            if (!F.isEmpty(rmvs))
-                cache.removeAll(rmvs);
-
-            if (!F.isEmpty(updates))
-                cache.putAll(updates);
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateQueryResultsRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateQueryResultsRegion.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateQueryResultsRegion.java
deleted file mode 100644
index 0b9a43d..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateQueryResultsRegion.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.apache.ignite.Ignite;
-import org.hibernate.Query;
-import org.hibernate.cache.spi.QueryResultsRegion;
-
-/**
- * Implementation of {@link QueryResultsRegion}. This region is used to store query results.
- * <p>
- * Query results caching can be enabled in the Hibernate configuration file:
- * <pre name="code" class="xml">
- * &lt;hibernate-configuration&gt;
- *     &lt;!-- Enable L2 cache. --&gt;
- *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
- *
- *     &lt;!-- Enable query cache. --&gt;
- *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
-
- *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
- *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
- *
- *     &lt;!-- Specify entity. --&gt;
- *     &lt;mapping class="com.example.Entity"/&gt;
- *
- *     &lt;!-- Enable L2 cache with nonstrict-read-write access strategy for entity. --&gt;
- *     &lt;class-cache class="com.example.Entity" usage="nonstrict-read-write"/&gt;
- * &lt;/hibernate-configuration&gt;
- * </pre>
- * By default queries are not cached even after enabling query caching, to enable results caching for a particular
- * query, call {@link Query#setCacheable(boolean)}:
- * <pre name="code" class="java">
- *     Session ses = getSession();
- *
- *     Query qry = ses.createQuery("...");
- *
- *     qry.setCacheable(true); // Enable L2 cache for query.
- * </pre>
- * Note: the query cache does not cache the state of the actual entities in the cache, it caches only identifier
- * values. For this reason, the query cache should always be used in conjunction with
- * the second-level cache for those entities expected to be cached as part of a query result cache
- */
-public class HibernateQueryResultsRegion extends HibernateGeneralDataRegion implements QueryResultsRegion {
-    /**
-     * @param factory Region factory.
-     * @param name Region name.
-     * @param ignite Grid.
-     * @param cache Region cache.
-     */
-    public HibernateQueryResultsRegion(HibernateRegionFactory factory, String name,
-        Ignite ignite, HibernateCacheProxy cache) {
-        super(factory, name, ignite, cache);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadOnlyAccessStrategy.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadOnlyAccessStrategy.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadOnlyAccessStrategy.java
deleted file mode 100644
index cdef80e..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadOnlyAccessStrategy.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCheckedException;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cache.spi.access.SoftLock;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Implementation of {@link AccessType#READ_ONLY} cache access strategy.
- * <p>
- * Configuration of L2 cache and per-entity cache access strategy can be set in the
- * Hibernate configuration file:
- * <pre name="code" class="xml">
- * &lt;hibernate-configuration&gt;
- *     &lt;!-- Enable L2 cache. --&gt;
- *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
- *
- *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
- *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
- *
- *     &lt;!-- Specify entity. --&gt;
- *     &lt;mapping class="com.example.Entity"/&gt;
- *
- *     &lt;!-- Enable L2 cache with read-only access strategy for entity. --&gt;
- *     &lt;class-cache class="com.example.Entity" usage="read-only"/&gt;
- * &lt;/hibernate-configuration&gt;
- * </pre>
- * Also cache access strategy can be set using annotations:
- * <pre name="code" class="java">
- * &#064;javax.persistence.Entity
- * &#064;javax.persistence.Cacheable
- * &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
- * public class Entity { ... }
- * </pre>
-
- *
- */
-public class HibernateReadOnlyAccessStrategy extends HibernateAccessStrategyAdapter {
-    /**
-     * @param ignite Grid.
-     * @param cache Cache.
-     */
-    public HibernateReadOnlyAccessStrategy(Ignite ignite, HibernateCacheProxy cache) {
-        super(ignite, cache);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean insert(Object key, Object val) throws CacheException {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean afterInsert(Object key, Object val) throws CacheException {
-        try {
-            cache.put(key, val);
-
-            return true;
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override protected SoftLock lock(Object key) throws CacheException {
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void unlock(Object key, SoftLock lock) throws CacheException {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void remove(Object key) throws CacheException {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean update(Object key, Object val) throws CacheException {
-        throw new UnsupportedOperationException("Updates are not supported for read-only access strategy.");
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean afterUpdate(Object key, Object val, SoftLock lock) throws CacheException {
-        throw new UnsupportedOperationException("Updates are not supported for read-only access strategy.");
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadWriteAccessStrategy.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadWriteAccessStrategy.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadWriteAccessStrategy.java
deleted file mode 100644
index ae9bd71..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadWriteAccessStrategy.java
+++ /dev/null
@@ -1,328 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import java.util.Set;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
-import org.apache.ignite.internal.util.GridLeanSet;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cache.spi.access.SoftLock;
-
-import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
-import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
-
-/**
- * Implementation of {@link AccessType#READ_WRITE} cache access strategy.
- * <p>
- * Configuration of L2 cache and per-entity cache access strategy can be set in the
- * Hibernate configuration file:
- * <pre name="code" class="xml">
- * &lt;hibernate-configuration&gt;
- *     &lt;!-- Enable L2 cache. --&gt;
- *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
- *
- *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
- *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
- *
- *     &lt;!-- Specify entity. --&gt;
- *     &lt;mapping class="com.example.Entity"/&gt;
- *
- *     &lt;!-- Enable L2 cache with read-write access strategy for entity. --&gt;
- *     &lt;class-cache class="com.example.Entity" usage="read-write"/&gt;
- * &lt;/hibernate-configuration&gt;
- * </pre>
- * Also cache access strategy can be set using annotations:
- * <pre name="code" class="java">
- * &#064;javax.persistence.Entity
- * &#064;javax.persistence.Cacheable
- * &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
- * public class Entity { ... }
- * </pre>
- */
-public class HibernateReadWriteAccessStrategy extends HibernateAccessStrategyAdapter {
-    /** */
-    private final ThreadLocal<TxContext> txCtx;
-
-    /**
-     * @param ignite Grid.
-     * @param cache Cache.
-     * @param txCtx Thread local instance used to track updates done during one Hibernate transaction.
-     */
-    protected HibernateReadWriteAccessStrategy(Ignite ignite, HibernateCacheProxy cache, ThreadLocal txCtx) {
-        super(ignite, cache);
-
-        this.txCtx = (ThreadLocal<TxContext>)txCtx;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected Object get(Object key) throws CacheException {
-        boolean success = false;
-
-        try {
-            Object o = cache.get(key);
-
-            success = true;
-
-            return o;
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-        finally {
-            if (!success)
-                rollbackCurrentTx();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void putFromLoad(Object key, Object val) throws CacheException {
-        boolean success = false;
-
-        try {
-            cache.put(key, val);
-
-            success = true;
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-        finally {
-            if (!success)
-                rollbackCurrentTx();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected SoftLock lock(Object key) throws CacheException {
-        boolean success = false;
-
-        try {
-            TxContext ctx = txCtx.get();
-
-            if (ctx == null)
-                txCtx.set(ctx = new TxContext());
-
-            lockKey(key);
-
-            ctx.locked(key);
-
-            success = true;
-
-            return null;
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-        finally {
-            if (!success)
-                rollbackCurrentTx();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void unlock(Object key, SoftLock lock) throws CacheException {
-        boolean success = false;
-
-        try {
-            TxContext ctx = txCtx.get();
-
-            if (ctx != null)
-                unlock(ctx, key);
-
-            success = true;
-        }
-        catch (Exception e) {
-            throw new CacheException(e);
-        }
-        finally {
-            if (!success)
-                rollbackCurrentTx();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean update(Object key, Object val) throws CacheException {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean afterUpdate(Object key, Object val, SoftLock lock) throws CacheException {
-        boolean success = false;
-        boolean res = false;
-
-        try {
-            TxContext ctx = txCtx.get();
-
-            if (ctx != null) {
-                cache.put(key, val);
-
-                unlock(ctx, key);
-
-                res = true;
-            }
-
-            success = true;
-
-            return res;
-        }
-        catch (Exception e) {
-            throw new CacheException(e);
-        }
-        finally {
-            if (!success)
-                rollbackCurrentTx();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean insert(Object key, Object val) throws CacheException {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean afterInsert(Object key, Object val) throws CacheException {
-        boolean success = false;
-
-        try {
-            cache.put(key, val);
-
-            success = true;
-
-            return true;
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-        finally {
-            if (!success)
-                rollbackCurrentTx();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void remove(Object key) throws CacheException {
-        boolean success = false;
-
-        try {
-            TxContext ctx = txCtx.get();
-
-            if (ctx != null)
-                cache.remove(key);
-
-            success = true;
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-        finally {
-            if (!success)
-                rollbackCurrentTx();
-        }
-    }
-
-    /**
-     *
-     * @param ctx Transaction context.
-     * @param key Key.
-     * @throws CacheException If failed.
-     */
-    private void unlock(TxContext ctx, Object key) throws CacheException {
-        if (ctx.unlocked(key)) { // Finish transaction if last key is unlocked.
-            txCtx.remove();
-
-            GridNearTxLocal tx = cache.tx();
-
-            assert tx != null;
-
-            try {
-                tx.proxy().commit();
-            }
-            finally {
-                tx.proxy().close();
-            }
-
-            assert cache.tx() == null;
-        }
-    }
-
-    /**
-     * Roll backs current transaction.
-     */
-    private void rollbackCurrentTx() {
-        try {
-            TxContext ctx = txCtx.get();
-
-            if (ctx != null) {
-                txCtx.remove();
-
-                GridNearTxLocal tx = cache.tx();
-
-                if (tx != null)
-                    tx.proxy().rollback();
-            }
-        }
-        catch (IgniteException e) {
-            log.error("Failed to rollback cache transaction.", e);
-        }
-    }
-
-    /**
-     * @param key Key.
-     * @throws IgniteCheckedException If failed.
-     */
-    private void lockKey(Object key) throws IgniteCheckedException {
-        if (cache.tx() == null)
-            cache.txStart(PESSIMISTIC, REPEATABLE_READ);
-
-        cache.get(key); // Acquire distributed lock.
-    }
-
-    /**
-     * Information about updates done during single database transaction.
-     */
-    @SuppressWarnings("TypeMayBeWeakened")
-    private static class TxContext {
-        /** */
-        private Set<Object> locked = new GridLeanSet<>();
-
-        /**
-         * Marks key as locked.
-         *
-         * @param key Key.
-         */
-        void locked(Object key) {
-            locked.add(key);
-        }
-
-        /**
-         * Marks key as unlocked.
-         *
-         * @param key Key.
-         * @return {@code True} if last locked key was unlocked.
-         */
-        boolean unlocked(Object key) {
-            locked.remove(key);
-
-            return locked.isEmpty();
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegion.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegion.java
deleted file mode 100644
index 11a96d0..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegion.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import java.util.Collections;
-import java.util.Map;
-import org.apache.ignite.Ignite;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.Region;
-
-/**
- * Implementation of {@link Region}. This interface defines base contract for all L2 cache regions.
- */
-public class HibernateRegion implements Region {
-    /** */
-    protected final HibernateRegionFactory factory;
-
-    /** */
-    private final String name;
-
-    /** Cache instance. */
-    protected final HibernateCacheProxy cache;
-
-    /** Grid instance. */
-    protected Ignite ignite;
-
-    /**
-     * @param factory Region factory.
-     * @param name Region name.
-     * @param ignite Grid.
-     * @param cache Region cache.
-     */
-    public HibernateRegion(HibernateRegionFactory factory, String name, Ignite ignite, HibernateCacheProxy cache) {
-        this.factory = factory;
-        this.name = name;
-        this.ignite = ignite;
-        this.cache = cache;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String getName() {
-        return name;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void destroy() throws CacheException {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean contains(Object key) {
-        return cache.containsKey(key);
-    }
-
-    /** {@inheritDoc} */
-    @Override public long getSizeInMemory() {
-        return -1;
-    }
-
-    /** {@inheritDoc} */
-    @Override public long getElementCountInMemory() {
-        return cache.size();
-    }
-
-    /** {@inheritDoc} */
-    @Override public long getElementCountOnDisk() {
-        return -1;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Map toMap() {
-        return Collections.emptyMap();
-    }
-
-    /** {@inheritDoc} */
-    @Override public long nextTimestamp() {
-        return System.currentTimeMillis();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int getTimeout() {
-        return 0;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
deleted file mode 100644
index 0cf03d7..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
+++ /dev/null
@@ -1,255 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
-import org.apache.ignite.internal.util.typedef.G;
-import org.hibernate.boot.spi.SessionFactoryOptions;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.CacheDataDescription;
-import org.hibernate.cache.spi.CollectionRegion;
-import org.hibernate.cache.spi.EntityRegion;
-import org.hibernate.cache.spi.NaturalIdRegion;
-import org.hibernate.cache.spi.QueryResultsRegion;
-import org.hibernate.cache.spi.RegionFactory;
-import org.hibernate.cache.spi.TimestampsRegion;
-import org.hibernate.cache.spi.access.AccessType;
-
-import static org.hibernate.cache.spi.access.AccessType.NONSTRICT_READ_WRITE;
-
-/**
- * Hibernate L2 cache region factory.
- * <p>
- * Following Hibernate settings should be specified to enable second level cache and to use this
- * region factory for caching:
- * <pre name="code" class="brush: xml; gutter: false;">
- * hibernate.cache.use_second_level_cache=true
- * hibernate.cache.region.factory_class=org.apache.ignite.cache.hibernate.HibernateRegionFactory
- * </pre>
- * Note that before region factory is started you need to start properly configured Ignite node in the same JVM.
- * For example to start Ignite node one of loader provided in {@code org.apache.ignite.grid.startup} package can be used.
- * <p>
- * Name of Ignite instance to be used for region factory must be specified as following Hibernate property:
- * <pre name="code" class="brush: xml; gutter: false;">
- * org.apache.ignite.hibernate.ignite_instance_name=&lt;Ignite instance name&gt;
- * </pre>
- * Each Hibernate cache region must be associated with some {@link IgniteInternalCache}, by default it is assumed that
- * for each cache region there is a {@link IgniteInternalCache} with the same name. Also it is possible to define
- * region to cache mapping using properties with prefix {@code org.apache.ignite.hibernate.region_cache}.
- * For example if for region with name "region1" cache with name "cache1" should be used then following
- * Hibernate property should be specified:
- * <pre name="code" class="brush: xml; gutter: false;">
- * org.apache.ignite.hibernate.region_cache.region1=cache1
- * </pre>
- */
-public class HibernateRegionFactory implements RegionFactory {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /**
-     * Hibernate L2 cache grid name property name.
-     *
-     * @deprecated Use {@link #IGNITE_INSTANCE_NAME_PROPERTY}.
-     *      If {@link #IGNITE_INSTANCE_NAME_PROPERTY} is specified it takes precedence.
-     */
-    @Deprecated
-    public static final String GRID_NAME_PROPERTY = "org.apache.ignite.hibernate.grid_name";
-
-    /** Hibernate L2 cache Ignite instance name property name. */
-    public static final String IGNITE_INSTANCE_NAME_PROPERTY = "org.apache.ignite.hibernate.ignite_instance_name";
-
-    /** Default cache property name. */
-    public static final String DFLT_CACHE_NAME_PROPERTY = "org.apache.ignite.hibernate.default_cache";
-
-    /** Property prefix used to specify region name to cache name mapping. */
-    public static final String REGION_CACHE_PROPERTY = "org.apache.ignite.hibernate.region_cache.";
-
-    /** */
-    public static final String DFLT_ACCESS_TYPE_PROPERTY = "org.apache.ignite.hibernate.default_access_type";
-
-    /** */
-    public static final String GRID_CONFIG_PROPERTY = "org.apache.ignite.hibernate.grid_config";
-
-    /** Grid providing caches. */
-    private Ignite ignite;
-
-    /** Default cache. */
-    private HibernateCacheProxy dfltCache;
-
-    /** Default region access type. */
-    private AccessType dfltAccessType;
-
-    /** Region name to cache name mapping. */
-    private final Map<String, String> regionCaches = new HashMap<>();
-
-    /** Map needed to provide the same transaction context for different regions. */
-    private final ThreadLocal threadLoc = new ThreadLocal();
-
-    /** Key transformer. */
-    private final HibernateKeyTransformer hibernate4transformer = new HibernateKeyTransformer() {
-        @Override public Object transform(Object key) {
-            return key;
-        }
-    };
-
-    /** {@inheritDoc} */
-    @Override public void start(SessionFactoryOptions settings, Properties props) throws CacheException {
-        String gridCfg = props.getProperty(GRID_CONFIG_PROPERTY);
-        String igniteInstanceName = props.getProperty(IGNITE_INSTANCE_NAME_PROPERTY);
-
-        if (igniteInstanceName == null)
-            igniteInstanceName = props.getProperty(GRID_NAME_PROPERTY);
-
-        if (gridCfg != null) {
-            try {
-                ignite = G.start(gridCfg);
-            }
-            catch (IgniteException e) {
-                throw new CacheException(e);
-            }
-        }
-        else
-            ignite = Ignition.ignite(igniteInstanceName);
-
-        String accessType = props.getProperty(DFLT_ACCESS_TYPE_PROPERTY, NONSTRICT_READ_WRITE.name());
-
-        dfltAccessType = AccessType.valueOf(accessType);
-
-        for (Map.Entry<Object, Object> prop : props.entrySet()) {
-            String key = prop.getKey().toString();
-
-            if (key.startsWith(REGION_CACHE_PROPERTY)) {
-                String regionName = key.substring(REGION_CACHE_PROPERTY.length());
-
-                String cacheName = prop.getValue().toString();
-
-                if (((IgniteKernal)ignite).getCache(cacheName) == null)
-                    throw new CacheException("Cache '" + cacheName + "' specified for region '" + regionName + "' " +
-                        "is not configured.");
-
-                regionCaches.put(regionName, cacheName);
-            }
-        }
-
-        String dfltCacheName = props.getProperty(DFLT_CACHE_NAME_PROPERTY);
-
-        if (dfltCacheName != null) {
-            IgniteInternalCache<Object, Object> dfltCache = ((IgniteKernal)ignite).getCache(dfltCacheName);
-
-            if (dfltCache == null)
-                throw new CacheException("Cache specified as default is not configured: " + dfltCacheName);
-
-            this.dfltCache = new HibernateCacheProxy(dfltCache, hibernate4transformer);
-        }
-
-        IgniteLogger log = ignite.log().getLogger(HibernateRegionFactory.class);
-
-        if (log.isDebugEnabled())
-            log.debug("HibernateRegionFactory started [igniteInstanceName=" + igniteInstanceName + ']');
-    }
-
-    /** {@inheritDoc} */
-    @Override public void stop() {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isMinimalPutsEnabledByDefault() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public AccessType getDefaultAccessType() {
-        return dfltAccessType;
-    }
-
-    /** {@inheritDoc} */
-    @Override public long nextTimestamp() {
-        return System.currentTimeMillis();
-    }
-
-    /** {@inheritDoc} */
-    @Override public EntityRegion buildEntityRegion(String regionName, Properties props, CacheDataDescription metadata)
-        throws CacheException {
-        return new HibernateEntityRegion(this, regionName, ignite, regionCache(regionName), metadata);
-    }
-
-    /** {@inheritDoc} */
-    @Override public NaturalIdRegion buildNaturalIdRegion(String regionName, Properties props,
-        CacheDataDescription metadata) throws CacheException {
-        return new HibernateNaturalIdRegion(this, regionName, ignite, regionCache(regionName), metadata);
-    }
-
-    /** {@inheritDoc} */
-    @Override public CollectionRegion buildCollectionRegion(String regionName, Properties props,
-        CacheDataDescription metadata) throws CacheException {
-        return new HibernateCollectionRegion(this, regionName, ignite, regionCache(regionName), metadata);
-    }
-
-    /** {@inheritDoc} */
-    @Override public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties props)
-        throws CacheException {
-        return new HibernateQueryResultsRegion(this, regionName, ignite, regionCache(regionName));
-    }
-
-    /** {@inheritDoc} */
-    @Override public TimestampsRegion buildTimestampsRegion(String regionName, Properties props) throws CacheException {
-        return new HibernateTimestampsRegion(this, regionName, ignite, regionCache(regionName));
-    }
-
-    /**
-     * Reuse same thread local for the same cache across different regions.
-     *
-     * @param cacheName Cache name.
-     * @return Thread local instance used to track updates done during one Hibernate transaction.
-     */
-    ThreadLocal threadLocalForCache(String cacheName) {
-        return threadLoc;
-    }
-
-    /**
-     * @param regionName L2 cache region name.
-     * @return Cache for given region.
-     * @throws CacheException If cache for given region is not configured.
-     */
-    private HibernateCacheProxy regionCache(String regionName) throws CacheException {
-        String cacheName = regionCaches.get(regionName);
-
-        if (cacheName == null) {
-            if (dfltCache != null)
-                return dfltCache;
-
-            cacheName = regionName;
-        }
-
-        IgniteInternalCache<Object, Object> cache = ((IgniteKernal)ignite).getCache(cacheName);
-
-        if (cache == null)
-            throw new CacheException("Cache '" + cacheName + "' for region '" + regionName + "' is not configured.");
-
-        return new HibernateCacheProxy(cache, hibernate4transformer);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateTimestampsRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateTimestampsRegion.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateTimestampsRegion.java
deleted file mode 100644
index 8b4c243..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateTimestampsRegion.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.apache.ignite.Ignite;
-import org.hibernate.cache.spi.TimestampsRegion;
-
-/**
- * Implementation of {@link TimestampsRegion}. This region is automatically created when query
- * caching is enabled and it holds most recent updates timestamps to queryable tables.
- * Name of timestamps region is {@code "org.hibernate.cache.spi.UpdateTimestampsCache"}.
- */
-public class HibernateTimestampsRegion extends HibernateGeneralDataRegion implements TimestampsRegion {
-    /**
-     * @param factory Region factory.
-     * @param name Region name.
-     * @param ignite Grid.
-     * @param cache Region cache.
-     */
-    public HibernateTimestampsRegion(HibernateRegionFactory factory, String name,
-        Ignite ignite,  HibernateCacheProxy cache) {
-        super(factory, name, ignite, cache);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalAccessStrategy.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalAccessStrategy.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalAccessStrategy.java
deleted file mode 100644
index ca52849..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalAccessStrategy.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cache.spi.access.SoftLock;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Implementation of {@link AccessType#TRANSACTIONAL} cache access strategy.
- * <p>
- * It is supposed that this strategy is used in JTA environment and Hibernate and
- * {@link IgniteInternalCache} corresponding to the L2 cache region are configured to use the same transaction manager.
- * <p>
- * Configuration of L2 cache and per-entity cache access strategy can be set in the
- * Hibernate configuration file:
- * <pre name="code" class="xml">
- * &lt;hibernate-configuration&gt;
- *     &lt;!-- Enable L2 cache. --&gt;
- *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
- *
- *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
- *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
- *
- *     &lt;!-- Specify entity. --&gt;
- *     &lt;mapping class="com.example.Entity"/&gt;
- *
- *     &lt;!-- Enable L2 cache with transactional access strategy for entity. --&gt;
- *     &lt;class-cache class="com.example.Entity" usage="transactional"/&gt;
- * &lt;/hibernate-configuration&gt;
- * </pre>
- * Also cache access strategy can be set using annotations:
- * <pre name="code" class="java">
- * &#064;javax.persistence.Entity
- * &#064;javax.persistence.Cacheable
- * &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
- * public class Entity { ... }
- * </pre>
- */
-public class HibernateTransactionalAccessStrategy extends HibernateAccessStrategyAdapter {
-    /**
-     * @param ignite Grid.
-     * @param cache Cache.
-     */
-    public HibernateTransactionalAccessStrategy(Ignite ignite, HibernateCacheProxy cache) {
-        super(ignite, cache);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override protected Object get(Object key) throws CacheException {
-        try {
-            return cache.get(key);
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void putFromLoad(Object key, Object val) throws CacheException {
-        try {
-            cache.put(key, val);
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected SoftLock lock(Object key) throws CacheException {
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void unlock(Object key, SoftLock lock) throws CacheException {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean update(Object key, Object val) throws CacheException {
-        try {
-            cache.put(key, val);
-
-            return true;
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean afterUpdate(Object key, Object val, SoftLock lock) throws CacheException {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean insert(Object key, Object val) throws CacheException {
-        try {
-            cache.put(key, val);
-
-            return true;
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean afterInsert(Object key, Object val) throws CacheException {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void remove(Object key) throws CacheException {
-        try {
-            cache.remove(key);
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java
deleted file mode 100644
index 581076a..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.apache.ignite.Ignite;
-import org.apache.ignite.configuration.TransactionConfiguration;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.CacheDataDescription;
-import org.hibernate.cache.spi.CollectionRegion;
-import org.hibernate.cache.spi.EntityRegion;
-import org.hibernate.cache.spi.NaturalIdRegion;
-import org.hibernate.cache.spi.TransactionalDataRegion;
-import org.hibernate.cache.spi.access.AccessType;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
-
-/**
- * Implementation of {@link TransactionalDataRegion} (transactional means that
- * data in the region is updated in connection with database transaction).
- * This interface defines base contract for {@link EntityRegion}, {@link CollectionRegion}
- * and {@link NaturalIdRegion}.
- */
-public class HibernateTransactionalDataRegion extends HibernateRegion implements TransactionalDataRegion {
-    /** */
-    private final CacheDataDescription dataDesc;
-
-    /**
-     * @param factory Region factory.
-     * @param name Region name.
-     * @param ignite Grid.
-     * @param cache Region cache.
-     * @param dataDesc Region data description.
-     */
-    public HibernateTransactionalDataRegion(HibernateRegionFactory factory, String name,
-        Ignite ignite, HibernateCacheProxy cache, CacheDataDescription dataDesc) {
-        super(factory, name, ignite, cache);
-
-        this.dataDesc = dataDesc;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isTransactionAware() {
-        return false; // This method is not used by Hibernate.
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheDataDescription getCacheDataDescription() {
-        return dataDesc;
-    }
-
-    /**
-     * @param accessType Hibernate L2 cache access type.
-     * @return Access strategy for given access type.
-     */
-    protected HibernateAccessStrategyAdapter createAccessStrategy(AccessType accessType) {
-        switch (accessType) {
-            case READ_ONLY:
-                return new HibernateReadOnlyAccessStrategy(ignite, cache);
-
-            case NONSTRICT_READ_WRITE:
-                return new HibernateNonStrictAccessStrategy(ignite, cache, factory.threadLocalForCache(cache.name()));
-
-            case READ_WRITE:
-                if (cache.configuration().getAtomicityMode() != TRANSACTIONAL)
-                    throw new CacheException("Hibernate READ-WRITE access strategy must have Ignite cache with " +
-                        "'TRANSACTIONAL' atomicity mode: " + cache.name());
-
-                return new HibernateReadWriteAccessStrategy(ignite, cache, factory.threadLocalForCache(cache.name()));
-
-            case TRANSACTIONAL:
-                if (cache.configuration().getAtomicityMode() != TRANSACTIONAL)
-                    throw new CacheException("Hibernate TRANSACTIONAL access strategy must have Ignite cache with " +
-                        "'TRANSACTIONAL' atomicity mode: " + cache.name());
-
-                TransactionConfiguration txCfg = ignite.configuration().getTransactionConfiguration();
-
-                if (txCfg == null ||
-                    (txCfg.getTxManagerFactory() == null
-                    && txCfg.getTxManagerLookupClassName() == null
-                    && cache.configuration().getTransactionManagerLookupClassName() == null)) {
-                    throw new CacheException("Hibernate TRANSACTIONAL access strategy must have Ignite with " +
-                                "Factory<TransactionManager> configured (see IgniteConfiguration." +
-                                "getTransactionConfiguration().setTxManagerFactory()): " + cache.name());
-                }
-
-                return new HibernateTransactionalAccessStrategy(ignite, cache);
-
-            default:
-                throw new IllegalArgumentException("Unknown Hibernate access type: " + accessType);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/package-info.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/package-info.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/package-info.java
deleted file mode 100644
index 1179aec..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/hibernate/package-info.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * <!-- Package description. -->
- * Contains implementation of Hibernate L2 cache. Refer to
- * <i>org.apache.ignite.examples.datagrid.hibernate.HibernateL2CacheExample</i> for more information on how to
- * configure and use Ignite with Hibernate.
- */
-package org.apache.ignite.cache.hibernate;
\ No newline at end of file


[13/16] ignite git commit: ignite-1794 Refactored hibernate modules, switched to hibernate 5.1

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListenerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListenerSelfTest.java b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListenerSelfTest.java
new file mode 100644
index 0000000..880d12a
--- /dev/null
+++ b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListenerSelfTest.java
@@ -0,0 +1,238 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.store.hibernate;
+
+import java.io.Serializable;
+import java.util.Map;
+import javax.cache.Cache;
+import javax.cache.configuration.Factory;
+import javax.cache.integration.CacheLoaderException;
+import javax.cache.integration.CacheWriterException;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import org.apache.ignite.cache.store.CacheStore;
+import org.apache.ignite.cache.store.CacheStoreAdapter;
+import org.apache.ignite.cache.store.CacheStoreSession;
+import org.apache.ignite.cache.store.CacheStoreSessionListener;
+import org.apache.ignite.cache.store.CacheStoreSessionListenerAbstractSelfTest;
+import org.apache.ignite.cache.store.jdbc.CacheJdbcStoreSessionListener;
+import org.apache.ignite.lang.IgniteBiInClosure;
+import org.apache.ignite.resources.CacheStoreSessionResource;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+
+/**
+ * Tests for {@link CacheJdbcStoreSessionListener}.
+ */
+public class CacheHibernateStoreSessionListenerSelfTest extends CacheStoreSessionListenerAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected Factory<? extends CacheStore<Integer, Integer>> storeFactory() {
+        return new Factory<CacheStore<Integer, Integer>>() {
+            @Override public CacheStore<Integer, Integer> create() {
+                return new Store();
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Factory<CacheStoreSessionListener> sessionListenerFactory() {
+        return new Factory<CacheStoreSessionListener>() {
+            @Override public CacheStoreSessionListener create() {
+                CacheHibernateStoreSessionListener lsnr = new CacheHibernateStoreSessionListener();
+
+                SessionFactory sesFactory = new Configuration().
+                    setProperty("hibernate.connection.url", URL).
+                    addAnnotatedClass(Table1.class).
+                    addAnnotatedClass(Table2.class).
+                    buildSessionFactory();
+
+                lsnr.setSessionFactory(sesFactory);
+
+                return lsnr;
+            }
+        };
+    }
+
+    /**
+     */
+    private static class Store extends CacheStoreAdapter<Integer, Integer> {
+        /** */
+        private static String SES_CONN_KEY = "ses_conn";
+
+        /** */
+        @CacheStoreSessionResource
+        private CacheStoreSession ses;
+
+        /** {@inheritDoc} */
+        @Override public void loadCache(IgniteBiInClosure<Integer, Integer> clo, Object... args) {
+            loadCacheCnt.incrementAndGet();
+
+            checkSession();
+        }
+
+        /** {@inheritDoc} */
+        @Override public Integer load(Integer key) throws CacheLoaderException {
+            loadCnt.incrementAndGet();
+
+            checkSession();
+
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void write(Cache.Entry<? extends Integer, ? extends Integer> entry)
+            throws CacheWriterException {
+            writeCnt.incrementAndGet();
+
+            checkSession();
+
+            if (write.get()) {
+                Session hibSes = ses.attachment();
+
+                switch (ses.cacheName()) {
+                    case "cache1":
+                        hibSes.save(new Table1(entry.getKey(), entry.getValue()));
+
+                        break;
+
+                    case "cache2":
+                        if (fail.get())
+                            throw new CacheWriterException("Expected failure.");
+
+                        hibSes.save(new Table2(entry.getKey(), entry.getValue()));
+
+                        break;
+
+                    default:
+                        throw new CacheWriterException("Wring cache: " + ses.cacheName());
+                }
+            }
+        }
+
+        /** {@inheritDoc} */
+        @Override public void delete(Object key) throws CacheWriterException {
+            deleteCnt.incrementAndGet();
+
+            checkSession();
+        }
+
+        /** {@inheritDoc} */
+        @Override public void sessionEnd(boolean commit) {
+            assertNull(ses.attachment());
+        }
+
+        /**
+         */
+        private void checkSession() {
+            Session hibSes = ses.attachment();
+
+            assertNotNull(hibSes);
+
+            assertTrue(hibSes.isOpen());
+
+            Transaction tx = hibSes.getTransaction();
+
+            assertNotNull(tx);
+
+            if (ses.isWithinTransaction())
+                assertTrue(tx.isActive());
+            else
+                assertFalse(tx.isActive());
+
+            verifySameInstance(hibSes);
+        }
+
+        /**
+         * @param hibSes Session.
+         */
+        private void verifySameInstance(Session hibSes) {
+            Map<String, Session> props = ses.properties();
+
+            Session sesConn = props.get(SES_CONN_KEY);
+
+            if (sesConn == null)
+                props.put(SES_CONN_KEY, hibSes);
+            else {
+                assertSame(hibSes, sesConn);
+
+                reuseCnt.incrementAndGet();
+            }
+        }
+    }
+
+    /**
+     */
+    @Entity
+    @Table(name = "Table1")
+    private static class Table1 implements Serializable {
+        /** */
+        @Id @GeneratedValue
+        @Column(name = "id")
+        private Integer id;
+
+        /** */
+        @Column(name = "key")
+        private int key;
+
+        /** */
+        @Column(name = "value")
+        private int value;
+
+        /**
+         * @param key Key.
+         * @param value Value.
+         */
+        private Table1(int key, int value) {
+            this.key = key;
+            this.value = value;
+        }
+    }
+
+    /**
+     */
+    @Entity
+    @Table(name = "Table2")
+    private static class Table2 implements Serializable {
+        /** */
+        @Id @GeneratedValue
+        @Column(name = "id")
+        private Integer id;
+
+        /** */
+        @Column(name = "key")
+        private int key;
+
+        /** */
+        @Column(name = "value")
+        private int value;
+
+        /**
+         * @param key Key.
+         * @param value Value.
+         */
+        private Table2(int key, int value) {
+            this.key = key;
+            this.value = value;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml
new file mode 100644
index 0000000..3822b31
--- /dev/null
+++ b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+
+<!DOCTYPE hibernate-configuration PUBLIC
+        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
+        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
+
+<hibernate-configuration>
+    <session-factory>
+        <!-- Show SQL. -->
+        <property name="show_sql">true</property>
+
+        <!-- Database connection settings (private in-memory database). -->
+        <property name="connection.url">jdbc:h2:mem:example;DB_CLOSE_DELAY=-1</property>
+
+        <!-- Only validate the database schema on startup in production mode. -->
+        <property name="hbm2ddl.auto">update</property>
+
+        <!-- H2 dialect. -->
+        <property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
+
+        <!-- Mappings. -->
+        <mapping resource="org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml"/>
+    </session-factory>
+</hibernate-configuration>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/package-info.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/package-info.java b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/package-info.java
new file mode 100644
index 0000000..8af9886
--- /dev/null
+++ b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * <!-- Package description. -->
+ * Contains internal tests or test related classes and interfaces.
+ */
+package org.apache.ignite.cache.store.hibernate;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/java/org/apache/ignite/testsuites/IgniteBinaryHibernateTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/test/java/org/apache/ignite/testsuites/IgniteBinaryHibernateTestSuite.java b/modules/hibernate-4.2/src/test/java/org/apache/ignite/testsuites/IgniteBinaryHibernateTestSuite.java
new file mode 100644
index 0000000..3791bae
--- /dev/null
+++ b/modules/hibernate-4.2/src/test/java/org/apache/ignite/testsuites/IgniteBinaryHibernateTestSuite.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.testsuites;
+
+import junit.framework.TestSuite;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.testframework.config.GridTestProperties;
+
+/**
+ *
+ */
+public class IgniteBinaryHibernateTestSuite extends TestSuite {
+    /**
+     * @return Test suite.
+     * @throws Exception If failed.
+     */
+    public static TestSuite suite() throws Exception {
+        GridTestProperties.setProperty(GridTestProperties.MARSH_CLASS_NAME, BinaryMarshaller.class.getName());
+
+        return IgniteHibernateTestSuite.suite();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/java/org/apache/ignite/testsuites/IgniteHibernateTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/test/java/org/apache/ignite/testsuites/IgniteHibernateTestSuite.java b/modules/hibernate-4.2/src/test/java/org/apache/ignite/testsuites/IgniteHibernateTestSuite.java
new file mode 100644
index 0000000..99fea56
--- /dev/null
+++ b/modules/hibernate-4.2/src/test/java/org/apache/ignite/testsuites/IgniteHibernateTestSuite.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.testsuites;
+
+import junit.framework.TestSuite;
+import org.apache.ignite.cache.hibernate.HibernateL2CacheConfigurationSelfTest;
+import org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest;
+import org.apache.ignite.cache.hibernate.HibernateL2CacheTransactionalSelfTest;
+import org.apache.ignite.cache.hibernate.HibernateL2CacheTransactionalUseSyncSelfTest;
+import org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreNodeRestartTest;
+import org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreSelfTest;
+import org.apache.ignite.cache.store.hibernate.CacheHibernateStoreFactorySelfTest;
+import org.apache.ignite.cache.store.hibernate.CacheHibernateStoreSessionListenerSelfTest;
+
+/**
+ * Hibernate integration tests.
+ */
+public class IgniteHibernateTestSuite extends TestSuite {
+    /**
+     * @return Test suite.
+     * @throws Exception Thrown in case of the failure.
+     */
+    public static TestSuite suite() throws Exception {
+        TestSuite suite = new TestSuite("Hibernate Integration Test Suite");
+
+        // Hibernate L2 cache.
+        suite.addTestSuite(HibernateL2CacheSelfTest.class);
+        suite.addTestSuite(HibernateL2CacheTransactionalSelfTest.class);
+        suite.addTestSuite(HibernateL2CacheTransactionalUseSyncSelfTest.class);
+        suite.addTestSuite(HibernateL2CacheConfigurationSelfTest.class);
+
+        suite.addTestSuite(CacheHibernateBlobStoreSelfTest.class);
+
+        suite.addTestSuite(CacheHibernateBlobStoreNodeRestartTest.class);
+
+        suite.addTestSuite(CacheHibernateStoreSessionListenerSelfTest.class);
+
+        suite.addTestSuite(CacheHibernateStoreFactorySelfTest.class);
+
+        return suite;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/README.txt
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/README.txt b/modules/hibernate-5.1/README.txt
new file mode 100644
index 0000000..53c5d18
--- /dev/null
+++ b/modules/hibernate-5.1/README.txt
@@ -0,0 +1,48 @@
+Apache Ignite Hibernate Module
+------------------------------
+
+Apache Ignite Hibernate module provides Hibernate second-level cache (L2 cache) implementation based
+on Apache Ignite In-Memory Data Grid.
+
+To enable Hibernate module when starting a standalone node, move 'optional/ignite-hibernate5' folder to
+'libs' folder before running 'ignite.{sh|bat}' script. The content of the module folder will
+be added to classpath in this case.
+
+Importing Hibernate Module In Maven Project
+-------------------------------------------
+
+If you are using Maven to manage dependencies of your project, you can add Hibernate module
+dependency like this (replace '${ignite.version}' with actual Ignite version you are
+interested in):
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+                        http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    ...
+    <dependencies>
+        ...
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-hibernate_5.1</artifactId>
+            <version>${ignite.version}</version>
+        </dependency>
+        ...
+    </dependencies>
+    ...
+</project>
+
+
+LGPL dependencies
+-----------------
+
+Ignite includes the following optional LGPL dependencies:
+ - Hibernate L2 Cache Integration, http://hibernate.org/orm/
+ - JTS Topology Suite for Geospatial indexing, http://tsusiatsoftware.net/jts/main.html
+ - cron4j for cron-based task scheduling, http://www.sauronsoftware.it/projects/cron4j
+
+Apache binary releases cannot include LGPL dependencies. If you would like include
+optional LGPL dependencies into your release, you should download the source release
+from Ignite website and do the build with the following maven command:
+
+mvn clean package -DskipTests -Prelease,lgpl

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/licenses/apache-2.0.txt
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/licenses/apache-2.0.txt b/modules/hibernate-5.1/licenses/apache-2.0.txt
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/modules/hibernate-5.1/licenses/apache-2.0.txt
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/pom.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/pom.xml b/modules/hibernate-5.1/pom.xml
new file mode 100644
index 0000000..80299bc
--- /dev/null
+++ b/modules/hibernate-5.1/pom.xml
@@ -0,0 +1,159 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!--
+    POM file.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.ignite</groupId>
+        <artifactId>ignite-parent</artifactId>
+        <version>1</version>
+        <relativePath>../../parent</relativePath>
+    </parent>
+
+    <artifactId>ignite-hibernate_5.1</artifactId>
+    <version>2.0.0-SNAPSHOT</version>
+    <url>http://ignite.apache.org</url>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-core</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-hibernate-core</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.hibernate</groupId>
+            <artifactId>hibernate-core</artifactId>
+            <version>5.1.5.Final</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-jta</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.ow2.jotm</groupId>
+            <artifactId>jotm-core</artifactId>
+            <version>2.1.9</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>commons-dbcp</groupId>
+            <artifactId>commons-dbcp</artifactId>
+            <version>1.4</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.h2database</groupId>
+            <artifactId>h2</artifactId>
+            <version>${h2.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>javax.resource</groupId>
+            <artifactId>connector-api</artifactId>
+            <version>1.5</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-core</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-spring</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-log4j</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-beans</artifactId>
+            <version>${spring.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context</artifactId>
+            <version>${spring.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.thoughtworks.xstream</groupId>
+            <artifactId>xstream</artifactId>
+            <version>1.4.8</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <testResources>
+            <testResource>
+                <directory>src/main/java</directory>
+                <excludes>
+                    <exclude>**/*.java</exclude>
+                </excludes>
+            </testResource>
+            <testResource>
+                <directory>src/test/java</directory>
+                <excludes>
+                    <exclude>**/*.java</exclude>
+                </excludes>
+            </testResource>
+        </testResources>
+
+        <plugins>
+            <!-- Generate the OSGi MANIFEST.MF for this bundle. -->
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+</project>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateAbstractRegionAccessStrategy.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateAbstractRegionAccessStrategy.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateAbstractRegionAccessStrategy.java
new file mode 100644
index 0000000..c5829bf
--- /dev/null
+++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateAbstractRegionAccessStrategy.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.spi.access.RegionAccessStrategy;
+import org.hibernate.cache.spi.access.SoftLock;
+import org.hibernate.engine.spi.SessionImplementor;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Implementation of L2 cache access strategy delegating to {@link HibernateAccessStrategyAdapter}.
+ */
+public abstract class HibernateAbstractRegionAccessStrategy implements RegionAccessStrategy {
+    /** */
+    protected final HibernateAccessStrategyAdapter stgy;
+
+    /**
+     * @param stgy Access strategy implementation.
+     */
+    protected HibernateAbstractRegionAccessStrategy(HibernateAccessStrategyAdapter stgy) {
+        this.stgy = stgy;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public Object get(SessionImplementor ses, Object key, long txTs) throws CacheException {
+        return stgy.get(key);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean putFromLoad(SessionImplementor ses, Object key, Object val, long txTs, Object ver) throws CacheException {
+        stgy.putFromLoad(key, val);
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean putFromLoad(SessionImplementor ses, Object key, Object val, long txTs, Object ver, boolean minimalPutOverride)
+        throws CacheException {
+        stgy.putFromLoad(key, val, minimalPutOverride);
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public SoftLock lockItem(SessionImplementor ses, Object key, Object ver) throws CacheException {
+        stgy.lock(key);
+
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public SoftLock lockRegion() throws CacheException {
+        stgy.lockRegion();
+
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unlockRegion(SoftLock lock) throws CacheException {
+        stgy.unlockRegion();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unlockItem(SessionImplementor ses, Object key, SoftLock lock) throws CacheException {
+        stgy.unlock(key);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void remove(SessionImplementor ses, Object key) throws CacheException {
+        stgy.remove(key);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void removeAll() throws CacheException {
+        stgy.removeAll();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void evict(Object key) throws CacheException {
+        stgy.evict(key);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void evictAll() throws CacheException {
+        stgy.evictAll();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java
new file mode 100644
index 0000000..be99e98
--- /dev/null
+++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import org.apache.ignite.Ignite;
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.spi.CacheDataDescription;
+import org.hibernate.cache.spi.CollectionRegion;
+import org.hibernate.cache.spi.access.AccessType;
+import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
+import org.hibernate.engine.spi.SessionFactoryImplementor;
+import org.hibernate.persister.collection.CollectionPersister;
+
+/**
+ * Implementation of {@link CollectionRegion}. This region is used to store collection data.
+ * <p>
+ * L2 cache for collection can be enabled in the Hibernate configuration file:
+ * <pre name="code" class="xml">
+ * &lt;hibernate-configuration&gt;
+ *     &lt;!-- Enable L2 cache. --&gt;
+ *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
+ *
+ *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
+ *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
+ *
+ *     &lt;!-- Specify entities. --&gt;
+ *     &lt;mapping class="com.example.Entity"/&gt;
+ *     &lt;mapping class="com.example.ChildEntity"/&gt;
+ *
+ *     &lt;!-- Enable L2 cache with nonstrict-read-write access strategy for entities and collection. --&gt;
+ *     &lt;collection-cache collection="com.example.Entity" usage="nonstrict-read-write"/&gt;
+ *     &lt;collection-cache collection="com.example.ChildEntity" usage="nonstrict-read-write"/&gt;
+ *     &lt;collection-cache collection="com.example.Entity.children" usage="nonstrict-read-write"/&gt;
+ * &lt;/hibernate-configuration&gt;
+ * </pre>
+ * Also cache for collection can be enabled using annotations:
+ * <pre name="code" class="java">
+ * &#064;javax.persistence.Entity
+ * public class Entity {
+ *    ...
+ *
+ *    &#064;javax.persistence.OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
+ *    &#064;javax.persistence.JoinColumn(name="PARENT_ID")
+ *    &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+ *    public List&lt;ChildEntity&gt; getChildren() {...}
+ * }
+ * </pre>
+ * Note: the collection cache does not cache the state of the actual entities in the cache, it caches only identifier
+ * values. For this reason, the collection cache should always be used in conjunction with
+ * the second-level cache for those entities expected to be cached as part of a collection cache.
+ */
+public class HibernateCollectionRegion extends HibernateTransactionalDataRegion implements CollectionRegion {
+    /**
+     * @param factory Region factory.
+     * @param name Region name.
+     * @param ignite Grid.
+     * @param cache Region cache.
+     * @param dataDesc Region data description.
+     */
+    public HibernateCollectionRegion(HibernateRegionFactory factory, String name,
+        Ignite ignite, HibernateCacheProxy cache, CacheDataDescription dataDesc) {
+        super(factory, name, ignite, cache, dataDesc);
+    }
+
+    /** {@inheritDoc} */
+    @Override public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
+        return new AccessStrategy(createAccessStrategy(accessType));
+    }
+
+    /**
+     * Collection region access strategy.
+     */
+    private class AccessStrategy extends HibernateAbstractRegionAccessStrategy
+        implements CollectionRegionAccessStrategy {
+        /**
+         * @param stgy Access strategy implementation.
+         */
+        private AccessStrategy(HibernateAccessStrategyAdapter stgy) {
+            super(stgy);
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object generateCacheKey(Object id,
+            CollectionPersister persister,
+            SessionFactoryImplementor factory, String tenantIdentifier) {
+            return HibernateKeyWrapper.staticCreateCollectionKey(id, persister, tenantIdentifier);
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object getCacheKeyId(Object cacheKey) {
+            return ((HibernateKeyWrapper)cacheKey).id();
+        }
+
+        /** {@inheritDoc} */
+        @Override public CollectionRegion getRegion() {
+            return HibernateCollectionRegion.this;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java
new file mode 100644
index 0000000..c669400
--- /dev/null
+++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import org.apache.ignite.Ignite;
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.spi.CacheDataDescription;
+import org.hibernate.cache.spi.EntityRegion;
+import org.hibernate.cache.spi.access.AccessType;
+import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
+import org.hibernate.cache.spi.access.SoftLock;
+import org.hibernate.engine.spi.SessionFactoryImplementor;
+import org.hibernate.engine.spi.SessionImplementor;
+import org.hibernate.persister.entity.EntityPersister;
+
+/**
+ * Implementation of {@link EntityRegion}. This region is used to store entity data.
+ * <p>
+ * L2 cache for entity can be enabled in the Hibernate configuration file:
+ * <pre name="code" class="xml">
+ * &lt;hibernate-configuration&gt;
+ *     &lt;!-- Enable L2 cache. --&gt;
+ *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
+ *
+ *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
+ *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
+ *
+ *     &lt;!-- Specify entity. --&gt;
+ *     &lt;mapping class="com.example.Entity"/&gt;
+ *
+ *     &lt;!-- Enable L2 cache with nonstrict-read-write access strategy for entity. --&gt;
+ *     &lt;class-cache class="com.example.Entity" usage="nonstrict-read-write"/&gt;
+ * &lt;/hibernate-configuration&gt;
+ * </pre>
+ * Also cache for entity can be enabled using annotations:
+ * <pre name="code" class="java">
+ * &#064;javax.persistence.Entity
+ * &#064;javax.persistence.Cacheable
+ * &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+ * public class Entity { ... }
+ * </pre>
+ */
+public class HibernateEntityRegion extends HibernateTransactionalDataRegion implements EntityRegion {
+    /**
+     * @param factory Region factory.
+     * @param name Region name.
+     * @param ignite Grid.
+     * @param cache Region cache,
+     * @param dataDesc Region data description.
+     */
+    public HibernateEntityRegion(HibernateRegionFactory factory, String name, Ignite ignite,
+        HibernateCacheProxy cache, CacheDataDescription dataDesc) {
+        super(factory, name, ignite, cache, dataDesc);
+    }
+
+    /** {@inheritDoc} */
+    @Override public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
+        return new AccessStrategy(createAccessStrategy(accessType));
+    }
+
+    /**
+     * Entity region access strategy.
+     */
+    private class AccessStrategy extends HibernateAbstractRegionAccessStrategy
+        implements EntityRegionAccessStrategy {
+        /**
+         * @param stgy Access strategy implementation.
+         */
+        private AccessStrategy(HibernateAccessStrategyAdapter stgy) {
+            super(stgy);
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object generateCacheKey(Object id,
+            EntityPersister persister,
+            SessionFactoryImplementor factory,
+            String tenantIdentifier) {
+            return HibernateKeyWrapper.staticCreateEntityKey(id, persister, tenantIdentifier);
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object getCacheKeyId(Object cacheKey) {
+            return ((HibernateKeyWrapper)cacheKey).id();
+        }
+
+        /** {@inheritDoc} */
+        @Override public EntityRegion getRegion() {
+            return HibernateEntityRegion.this;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean insert(SessionImplementor ses, Object key, Object val, Object ver) throws CacheException {
+            return stgy.insert(key, val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean afterInsert(SessionImplementor ses, Object key, Object val, Object ver) throws CacheException {
+            return stgy.afterInsert(key, val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean update(SessionImplementor ses, Object key, Object val, Object currVer, Object previousVer)
+            throws CacheException {
+            return stgy.update(key, val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean afterUpdate(SessionImplementor ses, Object key, Object val, Object currVer, Object previousVer, SoftLock lock)
+            throws CacheException {
+            return stgy.afterUpdate(key, val);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateGeneralDataRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateGeneralDataRegion.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateGeneralDataRegion.java
new file mode 100644
index 0000000..9365157
--- /dev/null
+++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateGeneralDataRegion.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCheckedException;
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.spi.GeneralDataRegion;
+import org.hibernate.cache.spi.QueryResultsRegion;
+import org.hibernate.cache.spi.TimestampsRegion;
+import org.hibernate.engine.spi.SessionImplementor;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Implementation of {@link GeneralDataRegion}. This interface defines common contract for {@link QueryResultsRegion}
+ * and {@link TimestampsRegion}.
+ */
+public class HibernateGeneralDataRegion extends HibernateRegion implements GeneralDataRegion {
+    /**
+     * @param factory Region factory.
+     * @param name Region name.
+     * @param ignite Grid.
+     * @param cache Region cache.
+     */
+    HibernateGeneralDataRegion(HibernateRegionFactory factory, String name,
+        Ignite ignite, HibernateCacheProxy cache) {
+        super(factory, name, ignite, cache);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public Object get(SessionImplementor ses, Object key) throws CacheException {
+        try {
+            return cache.get(key);
+        }
+        catch (IgniteCheckedException e) {
+            throw new CacheException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void put(SessionImplementor ses, Object key, Object val) throws CacheException {
+        try {
+            cache.put(key, val);
+        }
+        catch (IgniteCheckedException e) {
+            throw new CacheException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void evict(Object key) throws CacheException {
+        HibernateAccessStrategyAdapter.evict(ignite, cache, key);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void evictAll() throws CacheException {
+        try {
+            HibernateAccessStrategyAdapter.evictAll(cache);
+        }
+        catch (IgniteCheckedException e) {
+            throw HibernateRegionFactory.EXCEPTION_CONVERTER.convert(e);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
new file mode 100644
index 0000000..45d00e4
--- /dev/null
+++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import java.io.Serializable;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.hibernate.cache.internal.DefaultCacheKeysFactory;
+import org.hibernate.engine.spi.SessionFactoryImplementor;
+import org.hibernate.persister.collection.CollectionPersister;
+import org.hibernate.persister.entity.EntityPersister;
+
+/**
+ * Hibernate cache key wrapper.
+ */
+public class HibernateKeyWrapper implements Serializable {
+    /** Key. */
+    private final Object key;
+
+    /** Entry. */
+    private final String entry;
+
+    /** */
+    private final String tenantId;
+
+    /**
+     * @param key Key.
+     * @param entry Entry.
+     * @param tenantId Tenant ID.
+     */
+    HibernateKeyWrapper(Object key, String entry, String tenantId) {
+        this.key = key;
+        this.entry = entry;
+        this.tenantId = tenantId;
+    }
+
+    /**
+     * @return ID.
+     */
+    Object id() {
+        return key;
+    }
+
+    /**
+     * @param id ID.
+     * @param persister Persister.
+     * @param tenantIdentifier Tenant ID.
+     * @return Cache key.
+     * @see DefaultCacheKeysFactory#staticCreateCollectionKey(Object, CollectionPersister, SessionFactoryImplementor, String)
+     */
+    static Object staticCreateCollectionKey(Object id,
+        CollectionPersister persister,
+        String tenantIdentifier) {
+        return new HibernateKeyWrapper(id, persister.getRole(), tenantIdentifier);
+    }
+
+    /**
+     * @param id ID.
+     * @param persister Persister.
+     * @param tenantIdentifier Tenant ID.
+     * @return Cache key.
+     * @see DefaultCacheKeysFactory#staticCreateEntityKey(Object, EntityPersister, SessionFactoryImplementor, String)
+     */
+    public static Object staticCreateEntityKey(Object id, EntityPersister persister, String tenantIdentifier) {
+        return new HibernateKeyWrapper(id, persister.getRootEntityName(), tenantIdentifier);
+    }
+
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o) return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        HibernateKeyWrapper that = (HibernateKeyWrapper) o;
+
+        return (key != null ? key.equals(that.key) : that.key == null) &&
+            (entry != null ? entry.equals(that.entry) : that.entry == null) &&
+            (tenantId != null ? tenantId.equals(that.tenantId) : that.tenantId == null);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = key != null ? key.hashCode() : 0;
+        res = 31 * res + (entry != null ? entry.hashCode() : 0);
+        res = 31 * res + (tenantId != null ? tenantId.hashCode() : 0);
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(HibernateKeyWrapper.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateNaturalIdRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateNaturalIdRegion.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateNaturalIdRegion.java
new file mode 100644
index 0000000..68816de
--- /dev/null
+++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateNaturalIdRegion.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import org.apache.ignite.Ignite;
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.internal.DefaultCacheKeysFactory;
+import org.hibernate.cache.spi.CacheDataDescription;
+import org.hibernate.cache.spi.NaturalIdRegion;
+import org.hibernate.cache.spi.access.AccessType;
+import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy;
+import org.hibernate.cache.spi.access.SoftLock;
+import org.hibernate.engine.spi.SessionImplementor;
+import org.hibernate.persister.entity.EntityPersister;
+
+/**
+ * Implementation of {@link NaturalIdRegion}. This region is used to store naturalId data.
+ * <p>
+ * L2 cache for entity naturalId and target cache region can be set using annotations:
+ * <pre name="code" class="java">
+ * &#064;javax.persistence.Entity
+ * &#064;javax.persistence.Cacheable
+ * &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+ * &#064;org.hibernate.annotations.NaturalIdCache
+ * public class Entity {
+ *     &#064;org.hibernate.annotations.NaturalId
+ *     private String entityCode;
+ *
+ *     ...
+ * }
+ * </pre>
+ */
+public class HibernateNaturalIdRegion extends HibernateTransactionalDataRegion implements NaturalIdRegion {
+    /**
+     * @param factory Region factory.
+     * @param name Region name.
+     * @param ignite Grid.
+     * @param cache Region cache,
+     * @param dataDesc Region data description.
+     */
+    public HibernateNaturalIdRegion(HibernateRegionFactory factory, String name,
+        Ignite ignite, HibernateCacheProxy cache, CacheDataDescription dataDesc) {
+        super(factory, name, ignite, cache, dataDesc);
+    }
+
+    /** {@inheritDoc} */
+    @Override public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
+        return new AccessStrategy(createAccessStrategy(accessType));
+    }
+
+    /**
+     * NaturalId region access strategy.
+     */
+    private class AccessStrategy extends HibernateAbstractRegionAccessStrategy implements
+        NaturalIdRegionAccessStrategy {
+        /**
+         * @param stgy Access strategy implementation.
+         */
+        private AccessStrategy(HibernateAccessStrategyAdapter stgy) {
+            super(stgy);
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SessionImplementor ses) {
+            return DefaultCacheKeysFactory.staticCreateNaturalIdKey(naturalIdValues, persister, ses);
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object[] getNaturalIdValues(Object cacheKey) {
+            return DefaultCacheKeysFactory.staticGetNaturalIdValues(cacheKey);
+        }
+
+        /** {@inheritDoc} */
+        @Override public NaturalIdRegion getRegion() {
+            return HibernateNaturalIdRegion.this;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean insert(SessionImplementor ses, Object key, Object val) throws CacheException {
+            return stgy.insert(key, val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean afterInsert(SessionImplementor ses, Object key, Object val) throws CacheException {
+            return stgy.afterInsert(key, val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean update(SessionImplementor ses, Object key, Object val) throws CacheException {
+            return stgy.update(key, val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean afterUpdate(SessionImplementor ses, Object key, Object val, SoftLock lock) throws CacheException {
+            return stgy.afterUpdate(key, val);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateQueryResultsRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateQueryResultsRegion.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateQueryResultsRegion.java
new file mode 100644
index 0000000..0b9a43d
--- /dev/null
+++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateQueryResultsRegion.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import org.apache.ignite.Ignite;
+import org.hibernate.Query;
+import org.hibernate.cache.spi.QueryResultsRegion;
+
+/**
+ * Implementation of {@link QueryResultsRegion}. This region is used to store query results.
+ * <p>
+ * Query results caching can be enabled in the Hibernate configuration file:
+ * <pre name="code" class="xml">
+ * &lt;hibernate-configuration&gt;
+ *     &lt;!-- Enable L2 cache. --&gt;
+ *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
+ *
+ *     &lt;!-- Enable query cache. --&gt;
+ *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
+
+ *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
+ *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
+ *
+ *     &lt;!-- Specify entity. --&gt;
+ *     &lt;mapping class="com.example.Entity"/&gt;
+ *
+ *     &lt;!-- Enable L2 cache with nonstrict-read-write access strategy for entity. --&gt;
+ *     &lt;class-cache class="com.example.Entity" usage="nonstrict-read-write"/&gt;
+ * &lt;/hibernate-configuration&gt;
+ * </pre>
+ * By default queries are not cached even after enabling query caching, to enable results caching for a particular
+ * query, call {@link Query#setCacheable(boolean)}:
+ * <pre name="code" class="java">
+ *     Session ses = getSession();
+ *
+ *     Query qry = ses.createQuery("...");
+ *
+ *     qry.setCacheable(true); // Enable L2 cache for query.
+ * </pre>
+ * Note: the query cache does not cache the state of the actual entities in the cache, it caches only identifier
+ * values. For this reason, the query cache should always be used in conjunction with
+ * the second-level cache for those entities expected to be cached as part of a query result cache
+ */
+public class HibernateQueryResultsRegion extends HibernateGeneralDataRegion implements QueryResultsRegion {
+    /**
+     * @param factory Region factory.
+     * @param name Region name.
+     * @param ignite Grid.
+     * @param cache Region cache.
+     */
+    public HibernateQueryResultsRegion(HibernateRegionFactory factory, String name,
+        Ignite ignite, HibernateCacheProxy cache) {
+        super(factory, name, ignite, cache);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegion.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegion.java
new file mode 100644
index 0000000..11a96d0
--- /dev/null
+++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegion.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.ignite.Ignite;
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.spi.Region;
+
+/**
+ * Implementation of {@link Region}. This interface defines base contract for all L2 cache regions.
+ */
+public class HibernateRegion implements Region {
+    /** */
+    protected final HibernateRegionFactory factory;
+
+    /** */
+    private final String name;
+
+    /** Cache instance. */
+    protected final HibernateCacheProxy cache;
+
+    /** Grid instance. */
+    protected Ignite ignite;
+
+    /**
+     * @param factory Region factory.
+     * @param name Region name.
+     * @param ignite Grid.
+     * @param cache Region cache.
+     */
+    public HibernateRegion(HibernateRegionFactory factory, String name, Ignite ignite, HibernateCacheProxy cache) {
+        this.factory = factory;
+        this.name = name;
+        this.ignite = ignite;
+        this.cache = cache;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getName() {
+        return name;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void destroy() throws CacheException {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean contains(Object key) {
+        return cache.containsKey(key);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long getSizeInMemory() {
+        return -1;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long getElementCountInMemory() {
+        return cache.size();
+    }
+
+    /** {@inheritDoc} */
+    @Override public long getElementCountOnDisk() {
+        return -1;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Map toMap() {
+        return Collections.emptyMap();
+    }
+
+    /** {@inheritDoc} */
+    @Override public long nextTimestamp() {
+        return System.currentTimeMillis();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int getTimeout() {
+        return 0;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
new file mode 100644
index 0000000..bf7d7e9
--- /dev/null
+++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import java.util.Properties;
+import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
+import org.hibernate.boot.spi.SessionFactoryOptions;
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.spi.CacheDataDescription;
+import org.hibernate.cache.spi.CollectionRegion;
+import org.hibernate.cache.spi.EntityRegion;
+import org.hibernate.cache.spi.NaturalIdRegion;
+import org.hibernate.cache.spi.QueryResultsRegion;
+import org.hibernate.cache.spi.RegionFactory;
+import org.hibernate.cache.spi.TimestampsRegion;
+import org.hibernate.cache.spi.access.AccessType;
+
+import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.DFLT_ACCESS_TYPE_PROPERTY;
+import static org.hibernate.cache.spi.access.AccessType.NONSTRICT_READ_WRITE;
+
+/**
+ * Hibernate L2 cache region factory.
+ * <p>
+ * Following Hibernate settings should be specified to enable second level cache and to use this
+ * region factory for caching:
+ * <pre name="code" class="brush: xml; gutter: false;">
+ * hibernate.cache.use_second_level_cache=true
+ * hibernate.cache.region.factory_class=org.apache.ignite.cache.hibernate.HibernateRegionFactory
+ * </pre>
+ * Note that before region factory is started you need to start properly configured Ignite node in the same JVM.
+ * For example to start Ignite node one of loader provided in {@code org.apache.ignite.grid.startup} package can be used.
+ * <p>
+ * Name of Ignite instance to be used for region factory must be specified as following Hibernate property:
+ * <pre name="code" class="brush: xml; gutter: false;">
+ * org.apache.ignite.hibernate.ignite_instance_name=&lt;Ignite instance name&gt;
+ * </pre>
+ * Each Hibernate cache region must be associated with some {@link IgniteInternalCache}, by default it is assumed that
+ * for each cache region there is a {@link IgniteInternalCache} with the same name. Also it is possible to define
+ * region to cache mapping using properties with prefix {@code org.apache.ignite.hibernate.region_cache}.
+ * For example if for region with name "region1" cache with name "cache1" should be used then following
+ * Hibernate property should be specified:
+ * <pre name="code" class="brush: xml; gutter: false;">
+ * org.apache.ignite.hibernate.region_cache.region1=cache1
+ * </pre>
+ */
+public class HibernateRegionFactory implements RegionFactory {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** */
+    static final HibernateExceptionConverter EXCEPTION_CONVERTER = new HibernateExceptionConverter() {
+        @Override public RuntimeException convert(Exception e) {
+            return new CacheException(e);
+        }
+    };
+
+    /** Default region access type. */
+    private AccessType dfltAccessType;
+
+    /** Key transformer. */
+    private final HibernateKeyTransformer hibernate4transformer = new HibernateKeyTransformer() {
+        @Override public Object transform(Object key) {
+            return key;
+        }
+    };
+
+    /** */
+    private final HibernateAccessStrategyFactory accessStgyFactory =
+        new HibernateAccessStrategyFactory(hibernate4transformer, EXCEPTION_CONVERTER);
+
+    /** {@inheritDoc} */
+    @Override public void start(SessionFactoryOptions settings, Properties props) throws CacheException {
+        String accessType = props.getProperty(DFLT_ACCESS_TYPE_PROPERTY, NONSTRICT_READ_WRITE.name());
+
+        dfltAccessType = AccessType.valueOf(accessType);
+
+        accessStgyFactory.start(props);
+    }
+
+    /**
+     * @return Access strategy factory.
+     */
+    HibernateAccessStrategyFactory accessStrategyFactory() {
+        return accessStgyFactory;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void stop() {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isMinimalPutsEnabledByDefault() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public AccessType getDefaultAccessType() {
+        return dfltAccessType;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long nextTimestamp() {
+        return System.currentTimeMillis();
+    }
+
+    /** {@inheritDoc} */
+    @Override public EntityRegion buildEntityRegion(String regionName, Properties props, CacheDataDescription metadata)
+        throws CacheException {
+        return new HibernateEntityRegion(this,
+            regionName,
+            accessStgyFactory.node(),
+            accessStgyFactory.regionCache(regionName),
+            metadata);
+    }
+
+    /** {@inheritDoc} */
+    @Override public NaturalIdRegion buildNaturalIdRegion(String regionName, Properties props,
+                                                          CacheDataDescription metadata) throws CacheException {
+        return new HibernateNaturalIdRegion(this,
+            regionName,
+            accessStgyFactory.node(),
+            accessStgyFactory.regionCache(regionName),
+            metadata);
+    }
+
+    /** {@inheritDoc} */
+    @Override public CollectionRegion buildCollectionRegion(String regionName, Properties props,
+                                                            CacheDataDescription metadata) throws CacheException {
+        return new HibernateCollectionRegion(this,
+            regionName,
+            accessStgyFactory.node(),
+            accessStgyFactory.regionCache(regionName),
+            metadata);
+    }
+
+    /** {@inheritDoc} */
+    @Override public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties props)
+        throws CacheException {
+        return new HibernateQueryResultsRegion(this,
+            regionName,
+            accessStgyFactory.node(),
+            accessStgyFactory.regionCache(regionName));
+    }
+
+    /** {@inheritDoc} */
+    @Override public TimestampsRegion buildTimestampsRegion(String regionName, Properties props) throws CacheException {
+        return new HibernateTimestampsRegion(this,
+            regionName,
+            accessStgyFactory.node(),
+            accessStgyFactory.regionCache(regionName));
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateTimestampsRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateTimestampsRegion.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateTimestampsRegion.java
new file mode 100644
index 0000000..8b4c243
--- /dev/null
+++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateTimestampsRegion.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import org.apache.ignite.Ignite;
+import org.hibernate.cache.spi.TimestampsRegion;
+
+/**
+ * Implementation of {@link TimestampsRegion}. This region is automatically created when query
+ * caching is enabled and it holds most recent updates timestamps to queryable tables.
+ * Name of timestamps region is {@code "org.hibernate.cache.spi.UpdateTimestampsCache"}.
+ */
+public class HibernateTimestampsRegion extends HibernateGeneralDataRegion implements TimestampsRegion {
+    /**
+     * @param factory Region factory.
+     * @param name Region name.
+     * @param ignite Grid.
+     * @param cache Region cache.
+     */
+    public HibernateTimestampsRegion(HibernateRegionFactory factory, String name,
+        Ignite ignite,  HibernateCacheProxy cache) {
+        super(factory, name, ignite, cache);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java
new file mode 100644
index 0000000..275ea9e
--- /dev/null
+++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import org.apache.ignite.Ignite;
+import org.hibernate.cache.spi.CacheDataDescription;
+import org.hibernate.cache.spi.CollectionRegion;
+import org.hibernate.cache.spi.EntityRegion;
+import org.hibernate.cache.spi.NaturalIdRegion;
+import org.hibernate.cache.spi.TransactionalDataRegion;
+import org.hibernate.cache.spi.access.AccessType;
+
+/**
+ * Implementation of {@link TransactionalDataRegion} (transactional means that
+ * data in the region is updated in connection with database transaction).
+ * This interface defines base contract for {@link EntityRegion}, {@link CollectionRegion}
+ * and {@link NaturalIdRegion}.
+ */
+public class HibernateTransactionalDataRegion extends HibernateRegion implements TransactionalDataRegion {
+    /** */
+    private final CacheDataDescription dataDesc;
+
+    /**
+     * @param factory Region factory.
+     * @param name Region name.
+     * @param ignite Grid.
+     * @param cache Region cache.
+     * @param dataDesc Region data description.
+     */
+    HibernateTransactionalDataRegion(HibernateRegionFactory factory, String name,
+        Ignite ignite, HibernateCacheProxy cache, CacheDataDescription dataDesc) {
+        super(factory, name, ignite, cache);
+
+        this.dataDesc = dataDesc;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isTransactionAware() {
+        return false; // This method is not used by Hibernate.
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheDataDescription getCacheDataDescription() {
+        return dataDesc;
+    }
+
+    /**
+     * @param accessType Hibernate L2 cache access type.
+     * @return Access strategy for given access type.
+     */
+    HibernateAccessStrategyAdapter createAccessStrategy(AccessType accessType) {
+        switch (accessType) {
+            case READ_ONLY:
+                return factory.accessStrategyFactory().createReadOnlyStrategy(cache);
+
+            case NONSTRICT_READ_WRITE:
+                return factory.accessStrategyFactory().createNonStrictReadWriteStrategy(cache);
+
+            case READ_WRITE:
+                return factory.accessStrategyFactory().createReadWriteStrategy(cache);
+
+            case TRANSACTIONAL:
+                return factory.accessStrategyFactory().createTransactionalStrategy(cache);
+
+            default:
+                throw new IllegalArgumentException("Unknown Hibernate access type: " + accessType);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/package-info.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/package-info.java b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/package-info.java
new file mode 100644
index 0000000..1179aec
--- /dev/null
+++ b/modules/hibernate-5.1/src/main/java/org/apache/ignite/cache/hibernate/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * <!-- Package description. -->
+ * Contains implementation of Hibernate L2 cache. Refer to
+ * <i>org.apache.ignite.examples.datagrid.hibernate.HibernateL2CacheExample</i> for more information on how to
+ * configure and use Ignite with Hibernate.
+ */
+package org.apache.ignite.cache.hibernate;
\ No newline at end of file


[07/16] ignite git commit: ignite-1794 Refactored hibernate modules, switched to hibernate 5.1

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java
deleted file mode 100644
index c87f08f..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java
+++ /dev/null
@@ -1,542 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.store.hibernate;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Map;
-import java.util.Properties;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.atomic.AtomicBoolean;
-import javax.cache.integration.CacheLoaderException;
-import javax.cache.integration.CacheWriterException;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.cache.store.CacheStore;
-import org.apache.ignite.cache.store.CacheStoreAdapter;
-import org.apache.ignite.cache.store.CacheStoreSession;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.internal.IgniteInterruptedCheckedException;
-import org.apache.ignite.internal.util.tostring.GridToStringExclude;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.marshaller.jdk.JdkMarshaller;
-import org.apache.ignite.resources.CacheStoreSessionResource;
-import org.apache.ignite.resources.IgniteInstanceResource;
-import org.apache.ignite.resources.LoggerResource;
-import org.apache.ignite.transactions.Transaction;
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.SharedSessionContract;
-import org.hibernate.cfg.Configuration;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * {@link CacheStore} implementation backed by Hibernate. This implementation
- * stores objects in underlying database in {@code BLOB} format.
- * <h2 class="header">Configuration</h2>
- * Either {@link #setSessionFactory(SessionFactory)} or
- * {@link #setHibernateConfigurationPath(String)} or
- * {@link #setHibernateProperties(Properties)} should be set.
- * <p>
- * If session factory is provided it should contain
- * {@link CacheHibernateBlobStoreEntry} persistent class (via provided
- * mapping file {@code GridCacheHibernateStoreEntry.hbm.xml} or by
- * adding {@link CacheHibernateBlobStoreEntry} to annotated classes
- * of session factory.
- * <p>
- * Path to hibernate configuration may be either an URL or a file path or
- * a classpath resource. This configuration file should include provided
- * mapping {@code GridCacheHibernateStoreEntry.hbm.xml} or include annotated
- * class {@link CacheHibernateBlobStoreEntry}.
- * <p>
- * If hibernate properties are provided, mapping
- * {@code GridCacheHibernateStoreEntry.hbm.xml} is included automatically.
- * <p>
- * Use {@link CacheHibernateBlobStoreFactory} factory to pass {@link CacheHibernateBlobStore} to {@link CacheConfiguration}.
- */
-public class CacheHibernateBlobStore<K, V> extends CacheStoreAdapter<K, V> {
-    /**
-     * Default connection URL
-     * (value is <tt>jdbc:h2:mem:hibernateCacheStore;DB_CLOSE_DELAY=-1;DEFAULT_LOCK_TIMEOUT=5000</tt>).
-     */
-    public static final String DFLT_CONN_URL = "jdbc:h2:mem:hibernateCacheStore;DB_CLOSE_DELAY=-1;" +
-        "DEFAULT_LOCK_TIMEOUT=5000";
-
-    /** Default show SQL property value (value is <tt>true</tt>). */
-    public static final String DFLT_SHOW_SQL = "true";
-
-    /** Default <tt>hibernate.hbm2ddl.auto</tt> property value (value is <tt>true</tt>). */
-    public static final String DFLT_HBM2DDL_AUTO = "update";
-
-    /** Session attribute name. */
-    private static final String ATTR_SES = "HIBERNATE_STORE_SESSION";
-
-    /** Name of Hibarname mapping resource. */
-    private static final String MAPPING_RESOURCE =
-            "org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml";
-
-    /** Marshaller. */
-    private static final Marshaller marsh = new JdkMarshaller();
-
-    /** Init guard. */
-    @GridToStringExclude
-    private final AtomicBoolean initGuard = new AtomicBoolean();
-
-    /** Init latch. */
-    @GridToStringExclude
-    private final CountDownLatch initLatch = new CountDownLatch(1);
-
-    /** Hibernate properties. */
-    @GridToStringExclude
-    private Properties hibernateProps;
-
-    /** Session factory. */
-    @GridToStringExclude
-    private SessionFactory sesFactory;
-
-    /** Path to hibernate configuration file. */
-    private String hibernateCfgPath;
-
-    /** Log. */
-    @LoggerResource
-    private IgniteLogger log;
-
-    /** Auto-injected store session. */
-    @CacheStoreSessionResource
-    private CacheStoreSession ses;
-
-    /** Ignite instance. */
-    @IgniteInstanceResource
-    private Ignite ignite;
-
-    /** {@inheritDoc} */
-    @SuppressWarnings({"unchecked", "RedundantTypeArguments"})
-    @Override public V load(K key) {
-        init();
-
-        Transaction tx = transaction();
-
-        if (log.isDebugEnabled())
-            log.debug("Store load [key=" + key + ", tx=" + tx + ']');
-
-        Session ses = session(tx);
-
-        try {
-            CacheHibernateBlobStoreEntry entry = (CacheHibernateBlobStoreEntry)
-                ses.get(CacheHibernateBlobStoreEntry.class, toBytes(key));
-
-            if (entry == null)
-                return null;
-
-            return fromBytes(entry.getValue());
-        }
-        catch (IgniteCheckedException | HibernateException e) {
-            rollback(ses, tx);
-
-            throw new CacheLoaderException("Failed to load value from cache store with key: " + key, e);
-        }
-        finally {
-            end(ses, tx);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void write(javax.cache.Cache.Entry<? extends K, ? extends V> entry) {
-        init();
-
-        Transaction tx = transaction();
-
-        K key = entry.getKey();
-        V val = entry.getValue();
-
-        if (log.isDebugEnabled())
-            log.debug("Store put [key=" + key + ", val=" + val + ", tx=" + tx + ']');
-
-        if (val == null) {
-            delete(key);
-
-            return;
-        }
-
-        Session ses = session(tx);
-
-        try {
-            CacheHibernateBlobStoreEntry entry0 = new CacheHibernateBlobStoreEntry(toBytes(key), toBytes(val));
-
-            ses.saveOrUpdate(entry0);
-        }
-        catch (IgniteCheckedException | HibernateException e) {
-            rollback(ses, tx);
-
-            throw new CacheWriterException("Failed to put value to cache store [key=" + key + ", val" + val + "]", e);
-        }
-        finally {
-            end(ses, tx);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings({"JpaQueryApiInspection", "JpaQlInspection"})
-    @Override public void delete(Object key) {
-        init();
-
-        Transaction tx = transaction();
-
-        if (log.isDebugEnabled())
-            log.debug("Store remove [key=" + key + ", tx=" + tx + ']');
-
-        Session ses = session(tx);
-
-        try {
-            Object obj = ses.get(CacheHibernateBlobStoreEntry.class, toBytes(key));
-
-            if (obj != null)
-                ses.delete(obj);
-        }
-        catch (IgniteCheckedException | HibernateException e) {
-            rollback(ses, tx);
-
-            throw new CacheWriterException("Failed to remove value from cache store with key: " + key, e);
-        }
-        finally {
-            end(ses, tx);
-        }
-    }
-
-    /**
-     * Rolls back hibernate session.
-     *
-     * @param ses Hibernate session.
-     * @param tx Cache ongoing transaction.
-     */
-    private void rollback(SharedSessionContract ses, Transaction tx) {
-        // Rollback only if there is no cache transaction,
-        // otherwise sessionEnd() will do all required work.
-        if (tx == null) {
-            org.hibernate.Transaction hTx = ses.getTransaction();
-
-            if (hTx != null && hTx.isActive())
-                hTx.rollback();
-        }
-    }
-
-    /**
-     * Ends hibernate session.
-     *
-     * @param ses Hibernate session.
-     * @param tx Cache ongoing transaction.
-     */
-    private void end(Session ses, Transaction tx) {
-        // Commit only if there is no cache transaction,
-        // otherwise sessionEnd() will do all required work.
-        if (tx == null) {
-            org.hibernate.Transaction hTx = ses.getTransaction();
-
-            if (hTx != null && hTx.isActive())
-                hTx.commit();
-
-            ses.close();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void sessionEnd(boolean commit) {
-        init();
-
-        Transaction tx = transaction();
-
-        Map<String, Session> props = session().properties();
-
-        Session ses = props.remove(ATTR_SES);
-
-        if (ses != null) {
-            org.hibernate.Transaction hTx = ses.getTransaction();
-
-            if (hTx != null) {
-                try {
-                    if (commit) {
-                        ses.flush();
-
-                        hTx.commit();
-                    }
-                    else
-                        hTx.rollback();
-
-                    if (log.isDebugEnabled())
-                        log.debug("Transaction ended [xid=" + tx.xid() + ", commit=" + commit + ']');
-                }
-                catch (HibernateException e) {
-                    throw new CacheWriterException("Failed to end transaction [xid=" + tx.xid() +
-                        ", commit=" + commit + ']', e);
-                }
-                finally {
-                    ses.close();
-                }
-            }
-        }
-    }
-
-    /**
-     * Gets Hibernate session.
-     *
-     * @param tx Cache transaction.
-     * @return Session.
-     */
-    Session session(@Nullable Transaction tx) {
-        Session ses;
-
-        if (tx != null) {
-            Map<String, Session> props = session().properties();
-
-            ses = props.get(ATTR_SES);
-
-            if (ses == null) {
-                ses = sesFactory.openSession();
-
-                ses.beginTransaction();
-
-                // Store session in transaction metadata, so it can be accessed
-                // for other operations on the same transaction.
-                props.put(ATTR_SES, ses);
-
-                if (log.isDebugEnabled())
-                    log.debug("Hibernate session open [ses=" + ses + ", tx=" + tx.xid() + "]");
-            }
-        }
-        else {
-            ses = sesFactory.openSession();
-
-            ses.beginTransaction();
-        }
-
-        return ses;
-    }
-
-    /**
-     * Sets session factory.
-     *
-     * @param sesFactory Session factory.
-     */
-    public void setSessionFactory(SessionFactory sesFactory) {
-        this.sesFactory = sesFactory;
-    }
-
-    /**
-     * Sets hibernate configuration path.
-     * <p>
-     * This may be either URL or file path or classpath resource.
-     *
-     * @param hibernateCfgPath URL or file path or classpath resource
-     *      pointing to hibernate configuration XML file.
-     */
-    public void setHibernateConfigurationPath(String hibernateCfgPath) {
-        this.hibernateCfgPath = hibernateCfgPath;
-    }
-
-    /**
-     * Sets Hibernate properties.
-     *
-     * @param hibernateProps Hibernate properties.
-     */
-    public void setHibernateProperties(Properties hibernateProps) {
-        this.hibernateProps = hibernateProps;
-    }
-
-    /**
-     * Initializes store.
-     *
-     * @throws IgniteException If failed to initialize.
-     */
-    private void init() throws IgniteException {
-        if (initGuard.compareAndSet(false, true)) {
-            if (log.isDebugEnabled())
-                log.debug("Initializing cache store.");
-
-            try {
-                if (sesFactory != null)
-                    // Session factory has been provided - nothing to do.
-                    return;
-
-                if (!F.isEmpty(hibernateCfgPath)) {
-                    try {
-                        URL url = new URL(hibernateCfgPath);
-
-                        sesFactory = new Configuration().configure(url).buildSessionFactory();
-
-                        if (log.isDebugEnabled())
-                            log.debug("Configured session factory using URL: " + url);
-
-                        // Session factory has been successfully initialized.
-                        return;
-                    }
-                    catch (MalformedURLException e) {
-                        if (log.isDebugEnabled())
-                            log.debug("Caught malformed URL exception: " + e.getMessage());
-                    }
-
-                    // Provided path is not a valid URL. File?
-                    File cfgFile = new File(hibernateCfgPath);
-
-                    if (cfgFile.exists()) {
-                        sesFactory = new Configuration().configure(cfgFile).buildSessionFactory();
-
-                        if (log.isDebugEnabled())
-                            log.debug("Configured session factory using file: " + hibernateCfgPath);
-
-                        // Session factory has been successfully initialized.
-                        return;
-                    }
-
-                    // Provided path is not a file. Classpath resource?
-                    sesFactory = new Configuration().configure(hibernateCfgPath).buildSessionFactory();
-
-                    if (log.isDebugEnabled())
-                        log.debug("Configured session factory using classpath resource: " + hibernateCfgPath);
-                }
-                else {
-                    if (hibernateProps == null) {
-                        U.warn(log, "No Hibernate configuration has been provided for store (will use default).");
-
-                        hibernateProps = new Properties();
-
-                        hibernateProps.setProperty("hibernate.connection.url", DFLT_CONN_URL);
-                        hibernateProps.setProperty("hibernate.show_sql", DFLT_SHOW_SQL);
-                        hibernateProps.setProperty("hibernate.hbm2ddl.auto", DFLT_HBM2DDL_AUTO);
-                    }
-
-                    Configuration cfg = new Configuration();
-
-                    cfg.setProperties(hibernateProps);
-
-                    assert resourceAvailable(MAPPING_RESOURCE) : MAPPING_RESOURCE;
-
-                    cfg.addResource(MAPPING_RESOURCE);
-
-                    sesFactory = cfg.buildSessionFactory();
-
-                    if (log.isDebugEnabled())
-                        log.debug("Configured session factory using properties: " + hibernateProps);
-                }
-            }
-            catch (HibernateException e) {
-                throw new IgniteException("Failed to initialize store.", e);
-            }
-            finally {
-                initLatch.countDown();
-            }
-        }
-        else if (initLatch.getCount() > 0) {
-            try {
-                U.await(initLatch);
-            }
-            catch (IgniteInterruptedCheckedException e) {
-                throw new IgniteException(e);
-            }
-        }
-
-        if (sesFactory == null)
-            throw new IgniteException("Cache store was not properly initialized.");
-    }
-
-    /**
-     * Checks availability of a classpath resource.
-     *
-     * @param name Resource name.
-     * @return {@code true} if resource is available and ready for read, {@code false} otherwise.
-     */
-    private boolean resourceAvailable(String name) {
-        InputStream cfgStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
-
-        if (cfgStream == null) {
-            log.error("Classpath resource not found: " + name);
-
-            return false;
-        }
-
-        try {
-            // Read a single byte to force actual content access by JVM.
-            cfgStream.read();
-
-            return true;
-        }
-        catch (IOException e) {
-            log.error("Failed to read classpath resource: " + name, e);
-
-            return false;
-        }
-        finally {
-            U.close(cfgStream, log);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(CacheHibernateBlobStore.class, this);
-    }
-
-    /**
-     * Serialize object to byte array using marshaller.
-     *
-     * @param obj Object to convert to byte array.
-     * @return Byte array.
-     * @throws IgniteCheckedException If failed to convert.
-     */
-    protected byte[] toBytes(Object obj) throws IgniteCheckedException {
-        return U.marshal(marsh, obj);
-    }
-
-    /**
-     * Deserialize object from byte array using marshaller.
-     *
-     * @param bytes Bytes to deserialize.
-     * @param <X> Result object type.
-     * @return Deserialized object.
-     * @throws IgniteCheckedException If failed.
-     */
-    protected <X> X fromBytes(byte[] bytes) throws IgniteCheckedException {
-        if (bytes == null || bytes.length == 0)
-            return null;
-
-        return U.unmarshal(marsh, bytes, getClass().getClassLoader());
-    }
-
-    /**
-     * @return Current transaction.
-     */
-    @Nullable private Transaction transaction() {
-        CacheStoreSession ses = session();
-
-        return ses != null ? ses.transaction() : null;
-    }
-
-    /**
-     * @return Store session.
-     */
-    private CacheStoreSession session() {
-        return ses;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml b/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml
deleted file mode 100644
index 5b0be43..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one or more
-  contributor license agreements.  See the NOTICE file distributed with
-  this work for additional information regarding copyright ownership.
-  The ASF licenses this file to You under the Apache License, Version 2.0
-  (the "License"); you may not use this file except in compliance with
-  the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-
-
-<!DOCTYPE hibernate-mapping PUBLIC
-        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
-        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
-
-<hibernate-mapping package="org.apache.ignite.examples.datagrid.store" default-access="field">
-    <class name="org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreEntry" table="ENTRIES">
-        <id name="key"/>
-
-        <property name="val"/>
-    </class>
-</hibernate-mapping>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.java
deleted file mode 100644
index d40c5ef..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.store.hibernate;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
-
-/**
- * Entry that is used by {@link CacheHibernateBlobStore} implementation.
- * <p>
- * Note that this is a reference implementation for tests only.
- * When running on production systems use concrete key-value types to
- * get better performance.
- */
-@Entity
-@Table(name = "ENTRIES")
-public class CacheHibernateBlobStoreEntry {
-    /** Key (use concrete key type in production). */
-    @Id
-    @Column(length = 65535)
-    private byte[] key;
-
-    /** Value (use concrete value type in production). */
-    @Column(length = 65535)
-    private byte[] val;
-
-    /**
-     * Constructor.
-     */
-    CacheHibernateBlobStoreEntry() {
-        // No-op.
-    }
-
-    /**
-     * Constructor.
-     *
-     * @param key Key.
-     * @param val Value.
-     */
-    CacheHibernateBlobStoreEntry(byte[] key, byte[] val) {
-        this.key = key;
-        this.val = val;
-    }
-
-    /**
-     * @return Key.
-     */
-    public byte[] getKey() {
-        return key;
-    }
-
-    /**
-     * @param key Key.
-     */
-    public void setKey(byte[] key) {
-        this.key = key;
-    }
-
-    /**
-     * @return Value.
-     */
-    public byte[] getValue() {
-        return val;
-    }
-
-    /**
-     * @param val Value.
-     */
-    public void setValue(byte[] val) {
-        this.val = val;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreFactory.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreFactory.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreFactory.java
deleted file mode 100644
index ea4df8a..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreFactory.java
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.store.hibernate;
-
-import java.util.Properties;
-import javax.cache.configuration.Factory;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.internal.IgniteComponentType;
-import org.apache.ignite.internal.util.spring.IgniteSpringHelper;
-import org.apache.ignite.internal.util.tostring.GridToStringExclude;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.resources.SpringApplicationContextResource;
-import org.hibernate.SessionFactory;
-
-/**
- * {@link Factory} implementation for {@link CacheHibernateBlobStore}.
- *
- * Use this factory to pass {@link CacheHibernateBlobStore} to {@link CacheConfiguration}.
- *
- * <h2 class="header">Java Example</h2>
- * In this example existing session factory is provided.
- * <pre name="code" class="java">
- *     ...
- *     CacheHibernateBlobStoreFactory&lt;String, String&gt; factory = new CacheHibernateBlobStoreFactory&lt;String, String&gt;();
- *
- *     factory.setSessionFactory(sesFactory);
- *     ...
- * </pre>
- *
- * <h2 class="header">Spring Example (using Spring ORM)</h2>
- * <pre name="code" class="xml">
- *   ...
- *   &lt;bean id=&quot;cache.hibernate.store.factory&quot;
- *       class=&quot;org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory&quot;&gt;
- *       &lt;property name=&quot;sessionFactory&quot;&gt;
- *           &lt;bean class=&quot;org.springframework.orm.hibernate3.LocalSessionFactoryBean&quot;&gt;
- *               &lt;property name=&quot;hibernateProperties&quot;&gt;
- *                   &lt;value&gt;
- *                       connection.url=jdbc:h2:mem:
- *                       show_sql=true
- *                       hbm2ddl.auto=true
- *                       hibernate.dialect=org.hibernate.dialect.H2Dialect
- *                   &lt;/value&gt;
- *               &lt;/property&gt;
- *               &lt;property name=&quot;mappingResources&quot;&gt;
- *                   &lt;list&gt;
- *                       &lt;value&gt;
- *                           org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml
- *                       &lt;/value&gt;
- *                   &lt;/list&gt;
- *               &lt;/property&gt;
- *           &lt;/bean&gt;
- *       &lt;/property&gt;
- *   &lt;/bean&gt;
- *   ...
- * </pre>
- *
- * <h2 class="header">Spring Example (using Spring ORM and persistent annotations)</h2>
- * <pre name="code" class="xml">
- *     ...
- *     &lt;bean id=&quot;cache.hibernate.store.factory1&quot;
- *         class=&quot;org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory&quot;&gt;
- *         &lt;property name=&quot;sessionFactory&quot;&gt;
- *             &lt;bean class=&quot;org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean&quot;&gt;
- *                 &lt;property name=&quot;hibernateProperties&quot;&gt;
- *                     &lt;value&gt;
- *                         connection.url=jdbc:h2:mem:
- *                         show_sql=true
- *                         hbm2ddl.auto=true
- *                         hibernate.dialect=org.hibernate.dialect.H2Dialect
- *                     &lt;/value&gt;
- *                 &lt;/property&gt;
- *                 &lt;property name=&quot;annotatedClasses&quot;&gt;
- *                     &lt;list&gt;
- *                         &lt;value&gt;
- *                             org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreEntry
- *                         &lt;/value&gt;
- *                     &lt;/list&gt;
- *                 &lt;/property&gt;
- *             &lt;/bean&gt;
- *         &lt;/property&gt;
- *     &lt;/bean&gt;
- *     ...
- * </pre>
- *
- * <h2 class="header">Spring Example</h2>
- * <pre name="code" class="xml">
- *     ...
- *     &lt;bean id=&quot;cache.hibernate.store.factory2&quot;
- *         class=&quot;org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory&quot;&gt;
- *         &lt;property name=&quot;hibernateProperties&quot;&gt;
- *             &lt;props&gt;
- *                 &lt;prop key=&quot;connection.url&quot;&gt;jdbc:h2:mem:&lt;/prop&gt;
- *                 &lt;prop key=&quot;hbm2ddl.auto&quot;&gt;update&lt;/prop&gt;
- *                 &lt;prop key=&quot;show_sql&quot;&gt;true&lt;/prop&gt;
- *             &lt;/props&gt;
- *         &lt;/property&gt;
- *     &lt;/bean&gt;
- *     ...
- * </pre>
- * <p>
- * <img src="http://ignite.apache.org/images/spring-small.png">
- * <br>
- * For information about Spring framework visit <a href="http://www.springframework.org/">www.springframework.org</a>
- */
-public class CacheHibernateBlobStoreFactory<K, V> implements Factory<CacheHibernateBlobStore<K, V>> {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** Session factory. */
-    @GridToStringExclude
-    private transient SessionFactory sesFactory;
-
-    /** Session factory bean name. */
-    private String sesFactoryBean;
-
-    /** Path to hibernate configuration file. */
-    private String hibernateCfgPath;
-
-    /** Hibernate properties. */
-    @GridToStringExclude
-    private Properties hibernateProps;
-
-    /** Application context. */
-    @SpringApplicationContextResource
-    private Object appContext;
-
-    /** {@inheritDoc} */
-    @Override public CacheHibernateBlobStore<K, V> create() {
-        CacheHibernateBlobStore<K, V> store = new CacheHibernateBlobStore<>();
-
-        store.setHibernateConfigurationPath(hibernateCfgPath);
-        store.setHibernateProperties(hibernateProps);
-
-        if (sesFactory != null)
-            store.setSessionFactory(sesFactory);
-        else if (sesFactoryBean != null) {
-            if (appContext == null)
-                throw new IgniteException("Spring application context resource is not injected.");
-
-            IgniteSpringHelper spring;
-
-            try {
-                spring = IgniteComponentType.SPRING.create(false);
-
-                SessionFactory sesFac = spring.loadBeanFromAppContext(appContext, sesFactoryBean);
-
-                store.setSessionFactory(sesFac);
-            }
-            catch (IgniteCheckedException e) {
-                throw new IgniteException("Failed to load bean in application context [beanName=" + sesFactoryBean +
-                        ", igniteConfig=" + appContext + ']');
-            }
-        }
-
-        return store;
-    }
-
-    /**
-     * Sets session factory.
-     *
-     * @param sesFactory Session factory.
-     * @return {@code This} for chaining.
-     * @see CacheHibernateBlobStore#setSessionFactory(SessionFactory)
-     */
-    public CacheHibernateBlobStoreFactory<K, V> setSessionFactory(SessionFactory sesFactory) {
-        this.sesFactory = sesFactory;
-
-        return this;
-    }
-
-    /**
-     * Sets name of the data source bean.
-     *
-     * @param sesFactory Session factory bean name.
-     * @return {@code This} for chaining.
-     * @see CacheHibernateBlobStore#setSessionFactory(SessionFactory)
-     */
-    public CacheHibernateBlobStoreFactory<K, V> setSessionFactoryBean(String sesFactory) {
-        this.sesFactoryBean = sesFactory;
-
-        return this;
-    }
-
-    /**
-     * Sets hibernate configuration path.
-     * <p>
-     * This may be either URL or file path or classpath resource.
-     *
-     * @param hibernateCfgPath URL or file path or classpath resource
-     *      pointing to hibernate configuration XML file.
-     * @return {@code This} for chaining.
-     * @see CacheHibernateBlobStore#setHibernateConfigurationPath(String)
-     */
-    public CacheHibernateBlobStoreFactory<K, V> setHibernateConfigurationPath(String hibernateCfgPath) {
-        this.hibernateCfgPath = hibernateCfgPath;
-
-        return this;
-    }
-
-    /**
-     * Sets Hibernate properties.
-     *
-     * @param hibernateProps Hibernate properties.
-     * @return {@code This} for chaining.
-     * @see CacheHibernateBlobStore#setHibernateProperties(Properties)
-     */
-    public CacheHibernateBlobStoreFactory<K, V> setHibernateProperties(Properties hibernateProps) {
-        this.hibernateProps = hibernateProps;
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(CacheHibernateBlobStoreFactory.class, this);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java
deleted file mode 100644
index 917641c..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.store.hibernate;
-
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
-import javax.cache.integration.CacheWriterException;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.cache.store.CacheStore;
-import org.apache.ignite.cache.store.CacheStoreSession;
-import org.apache.ignite.cache.store.CacheStoreSessionListener;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lifecycle.LifecycleAware;
-import org.apache.ignite.resources.LoggerResource;
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.Transaction;
-import org.hibernate.cfg.Configuration;
-
-/**
- * Hibernate-based cache store session listener.
- * <p>
- * This listener creates a new Hibernate session for each store
- * session. If there is an ongoing cache transaction, a corresponding
- * Hibernate transaction is created as well.
- * <p>
- * The Hibernate session is saved as a store session
- * {@link CacheStoreSession#attachment() attachment}.
- * The listener guarantees that the session will be
- * available for any store operation. If there is an
- * ongoing cache transaction, all operations within this
- * transaction will share a DB transaction.
- * <p>
- * As an example, here is how the {@link CacheStore#write(javax.cache.Cache.Entry)}
- * method can be implemented if {@link CacheHibernateStoreSessionListener}
- * is configured:
- * <pre name="code" class="java">
- * private static class Store extends CacheStoreAdapter&lt;Integer, Integer&gt; {
- *     &#64;CacheStoreSessionResource
- *     private CacheStoreSession ses;
- *
- *     &#64;Override public void write(Cache.Entry&lt;? extends Integer, ? extends Integer&gt; entry) throws CacheWriterException {
- *         // Get Hibernate session from the current store session.
- *         Session hibSes = ses.attachment();
- *
- *         // Persist the value.
- *         hibSes.persist(entry.getValue());
- *     }
- * }
- * </pre>
- * Hibernate session will be automatically created by the listener
- * at the start of the session and closed when it ends.
- * <p>
- * {@link CacheHibernateStoreSessionListener} requires that either
- * {@link #setSessionFactory(SessionFactory)} session factory}
- * or {@link #setHibernateConfigurationPath(String) Hibernate configuration file}
- * is provided. If non of them is set, exception is thrown. Is both are provided,
- * session factory will be used.
- */
-public class CacheHibernateStoreSessionListener implements CacheStoreSessionListener, LifecycleAware {
-    /** Hibernate session factory. */
-    private SessionFactory sesFactory;
-
-    /** Hibernate configuration file path. */
-    private String hibernateCfgPath;
-
-    /** Logger. */
-    @LoggerResource
-    private IgniteLogger log;
-
-    /** Whether to close session on stop. */
-    private boolean closeSesOnStop;
-
-    /**
-     * Sets Hibernate session factory.
-     * <p>
-     * Either session factory or configuration file is required.
-     * If none is provided, exception will be thrown on startup.
-     *
-     * @param sesFactory Session factory.
-     */
-    public void setSessionFactory(SessionFactory sesFactory) {
-        this.sesFactory = sesFactory;
-    }
-
-    /**
-     * Gets Hibernate session factory.
-     *
-     * @return Session factory.
-     */
-    public SessionFactory getSessionFactory() {
-        return sesFactory;
-    }
-
-    /**
-     * Sets hibernate configuration path.
-     * <p>
-     * Either session factory or configuration file is required.
-     * If none is provided, exception will be thrown on startup.
-     *
-     * @param hibernateCfgPath Hibernate configuration path.
-     */
-    public void setHibernateConfigurationPath(String hibernateCfgPath) {
-        this.hibernateCfgPath = hibernateCfgPath;
-    }
-
-    /**
-     * Gets hibernate configuration path.
-     *
-     * @return Hibernate configuration path.
-     */
-    public String getHibernateConfigurationPath() {
-        return hibernateCfgPath;
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("deprecation")
-    @Override public void start() throws IgniteException {
-        if (sesFactory == null && F.isEmpty(hibernateCfgPath))
-            throw new IgniteException("Either session factory or Hibernate configuration file is required by " +
-                getClass().getSimpleName() + '.');
-
-        if (!F.isEmpty(hibernateCfgPath)) {
-            if (sesFactory == null) {
-                try {
-                    URL url = new URL(hibernateCfgPath);
-
-                    sesFactory = new Configuration().configure(url).buildSessionFactory();
-                }
-                catch (MalformedURLException ignored) {
-                    // No-op.
-                }
-
-                if (sesFactory == null) {
-                    File cfgFile = new File(hibernateCfgPath);
-
-                    if (cfgFile.exists())
-                        sesFactory = new Configuration().configure(cfgFile).buildSessionFactory();
-                }
-
-                if (sesFactory == null)
-                    sesFactory = new Configuration().configure(hibernateCfgPath).buildSessionFactory();
-
-                if (sesFactory == null)
-                    throw new IgniteException("Failed to resolve Hibernate configuration file: " + hibernateCfgPath);
-
-                closeSesOnStop = true;
-            }
-            else
-                U.warn(log, "Hibernate configuration file configured in " + getClass().getSimpleName() +
-                    " will be ignored (session factory is already set).");
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void stop() throws IgniteException {
-        if (closeSesOnStop && sesFactory != null && !sesFactory.isClosed())
-            sesFactory.close();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void onSessionStart(CacheStoreSession ses) {
-        if (ses.attachment() == null) {
-            try {
-                Session hibSes = sesFactory.openSession();
-
-                ses.attach(hibSes);
-
-                if (ses.isWithinTransaction())
-                    hibSes.beginTransaction();
-            }
-            catch (HibernateException e) {
-                throw new CacheWriterException("Failed to start store session [tx=" + ses.transaction() + ']', e);
-            }
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void onSessionEnd(CacheStoreSession ses, boolean commit) {
-        Session hibSes = ses.attach(null);
-
-        if (hibSes != null) {
-            try {
-                Transaction tx = hibSes.getTransaction();
-
-                if (commit) {
-                    hibSes.flush();
-
-                    if (tx.isActive())
-                        tx.commit();
-                }
-                else if (tx.isActive())
-                    tx.rollback();
-            }
-            catch (HibernateException e) {
-                throw new CacheWriterException("Failed to end store session [tx=" + ses.transaction() + ']', e);
-            }
-            finally {
-                hibSes.close();
-            }
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/package-info.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/package-info.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/package-info.java
deleted file mode 100644
index 891d99a..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/store/hibernate/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * <!-- Package description. -->
- * Contains reference Hibernate-based cache store implementation.
- */
-package org.apache.ignite.cache.store.hibernate;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/test/config/factory-cache.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/test/config/factory-cache.xml b/modules/hibernate/src/test/config/factory-cache.xml
deleted file mode 100644
index a251846..0000000
--- a/modules/hibernate/src/test/config/factory-cache.xml
+++ /dev/null
@@ -1,59 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one or more
-  contributor license agreements.  See the NOTICE file distributed with
-  this work for additional information regarding copyright ownership.
-  The ASF licenses this file to You under the Apache License, Version 2.0
-  (the "License"); you may not use this file except in compliance with
-  the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-<beans xmlns="http://www.springframework.org/schema/beans"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="
-        http://www.springframework.org/schema/beans
-        http://www.springframework.org/schema/beans/spring-beans.xsd">
-
-    <bean id="simpleSessionFactory"
-          class="org.apache.ignite.cache.store.hibernate.CacheHibernateStoreFactorySelfTest$DummySessionFactoryExt"/>
-
-    <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
-        <property name="cacheConfiguration">
-            <list>
-                <bean class="org.apache.ignite.configuration.CacheConfiguration">
-                    <property name="name" value="test"/>
-                    <property name="atomicityMode" value="ATOMIC"/>
-                    <property name="backups" value="1"/>
-                    <property name="cacheStoreFactory">
-                        <bean class="org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory">
-                            <property name="sessionFactoryBean" value = "simpleSessionFactory"/>
-                        </bean>
-                    </property>
-                </bean>
-            </list>
-        </property>
-
-        <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
-        <property name="discoverySpi">
-            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
-                <property name="ipFinder">
-                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
-                        <property name="addresses">
-                            <list>
-                                <value>127.0.0.1:47500..47509</value>
-                            </list>
-                        </property>
-                    </bean>
-                </property>
-            </bean>
-        </property>
-    </bean>
-</beans>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/test/config/factory-cache1.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/test/config/factory-cache1.xml b/modules/hibernate/src/test/config/factory-cache1.xml
deleted file mode 100644
index 7a53b1f..0000000
--- a/modules/hibernate/src/test/config/factory-cache1.xml
+++ /dev/null
@@ -1,61 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one or more
-  contributor license agreements.  See the NOTICE file distributed with
-  this work for additional information regarding copyright ownership.
-  The ASF licenses this file to You under the Apache License, Version 2.0
-  (the "License"); you may not use this file except in compliance with
-  the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-<beans xmlns="http://www.springframework.org/schema/beans"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="
-        http://www.springframework.org/schema/beans
-        http://www.springframework.org/schema/beans/spring-beans.xsd">
-
-    <bean id="simpleSessionFactory1"
-          class="org.apache.ignite.cache.store.hibernate.CacheHibernateStoreFactorySelfTest$DummySessionFactory"/>
-
-    <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
-        <property name="igniteInstanceName" value="ignite1"/>
-
-        <property name="cacheConfiguration">
-            <list>
-                <bean class="org.apache.ignite.configuration.CacheConfiguration">
-                    <property name="name" value="test"/>
-                    <property name="atomicityMode" value="ATOMIC"/>
-                    <property name="backups" value="1"/>
-                    <property name="cacheStoreFactory">
-                        <bean class="org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory">
-                            <property name="sessionFactoryBean" value = "simpleSessionFactory1"/>
-                        </bean>
-                    </property>
-                </bean>
-            </list>
-        </property>
-
-        <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
-        <property name="discoverySpi">
-            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
-                <property name="ipFinder">
-                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
-                        <property name="addresses">
-                            <list>
-                                <value>127.0.0.1:47500..47509</value>
-                            </list>
-                        </property>
-                    </bean>
-                </property>
-            </bean>
-        </property>
-    </bean>
-</beans>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/test/config/factory-incorrect-store-cache.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/test/config/factory-incorrect-store-cache.xml b/modules/hibernate/src/test/config/factory-incorrect-store-cache.xml
deleted file mode 100644
index 459930c..0000000
--- a/modules/hibernate/src/test/config/factory-incorrect-store-cache.xml
+++ /dev/null
@@ -1,56 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one or more
-  contributor license agreements.  See the NOTICE file distributed with
-  this work for additional information regarding copyright ownership.
-  The ASF licenses this file to You under the Apache License, Version 2.0
-  (the "License"); you may not use this file except in compliance with
-  the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-<beans xmlns="http://www.springframework.org/schema/beans"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="
-        http://www.springframework.org/schema/beans
-        http://www.springframework.org/schema/beans/spring-beans.xsd">
-
-    <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
-        <property name="cacheConfiguration">
-            <list>
-                <bean class="org.apache.ignite.configuration.CacheConfiguration">
-                    <property name="name" value="test"/>
-                    <property name="atomicityMode" value="ATOMIC"/>
-                    <property name="backups" value="1"/>
-                    <property name="cacheStoreFactory">
-                        <bean class="org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory">
-                            <property name="sessionFactoryBean" value = "simpleSessionFactory1"/>
-                        </bean>
-                    </property>
-                </bean>
-            </list>
-        </property>
-
-        <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
-        <property name="discoverySpi">
-            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
-                <property name="ipFinder">
-                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
-                        <property name="addresses">
-                            <list>
-                                <value>127.0.0.1:47500..47509</value>
-                            </list>
-                        </property>
-                    </bean>
-                </property>
-            </bean>
-        </property>
-    </bean>
-</beans>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheConfigurationSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheConfigurationSelfTest.java b/modules/hibernate/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheConfigurationSelfTest.java
deleted file mode 100644
index b018d0b..0000000
--- a/modules/hibernate/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheConfigurationSelfTest.java
+++ /dev/null
@@ -1,408 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import javax.cache.Cache;
-import javax.persistence.Cacheable;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.Transaction;
-import org.hibernate.annotations.CacheConcurrencyStrategy;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.service.ServiceRegistryBuilder;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-import static org.apache.ignite.cache.hibernate.HibernateRegionFactory.DFLT_ACCESS_TYPE_PROPERTY;
-import static org.apache.ignite.cache.hibernate.HibernateRegionFactory.DFLT_CACHE_NAME_PROPERTY;
-import static org.apache.ignite.cache.hibernate.HibernateRegionFactory.IGNITE_INSTANCE_NAME_PROPERTY;
-import static org.apache.ignite.cache.hibernate.HibernateRegionFactory.REGION_CACHE_PROPERTY;
-import static org.hibernate.cfg.AvailableSettings.CACHE_REGION_FACTORY;
-import static org.hibernate.cfg.AvailableSettings.GENERATE_STATISTICS;
-import static org.hibernate.cfg.AvailableSettings.HBM2DDL_AUTO;
-import static org.hibernate.cfg.AvailableSettings.RELEASE_CONNECTIONS;
-import static org.hibernate.cfg.AvailableSettings.USE_QUERY_CACHE;
-import static org.hibernate.cfg.AvailableSettings.USE_SECOND_LEVEL_CACHE;
-
-/**
- * Tests Hibernate L2 cache configuration.
- */
-public class HibernateL2CacheConfigurationSelfTest extends GridCommonAbstractTest {
-    /** */
-    public static final String ENTITY1_NAME = Entity1.class.getName();
-
-    /** */
-    public static final String ENTITY2_NAME = Entity2.class.getName();
-
-    /** */
-    public static final String ENTITY3_NAME = Entity3.class.getName();
-
-    /** */
-    public static final String ENTITY4_NAME = Entity4.class.getName();
-
-    /** */
-    public static final String TIMESTAMP_CACHE = "org.hibernate.cache.spi.UpdateTimestampsCache";
-
-    /** */
-    public static final String QUERY_CACHE = "org.hibernate.cache.internal.StandardQueryCache";
-
-    /** */
-    public static final String CONNECTION_URL = "jdbc:h2:mem:example;DB_CLOSE_DELAY=-1";
-
-    /** If {@code true} then sets default cache in configuration. */
-    private boolean dfltCache;
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        startGrid(0);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        stopAllGrids();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        for (IgniteCacheProxy<?, ?> cache : ((IgniteKernal)grid(0)).caches())
-            cache.clear();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
-
-        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
-
-        discoSpi.setIpFinder(new TcpDiscoveryVmIpFinder(true));
-
-        cfg.setDiscoverySpi(discoSpi);
-
-        cfg.setCacheConfiguration(cacheConfiguration(ENTITY3_NAME), cacheConfiguration(ENTITY4_NAME),
-            cacheConfiguration("cache1"), cacheConfiguration("cache2"), cacheConfiguration("cache3"),
-            cacheConfiguration(TIMESTAMP_CACHE), cacheConfiguration(QUERY_CACHE));
-
-        return cfg;
-    }
-
-    /**
-     * @param cacheName Cache name.
-     * @return Cache configuration.
-     */
-    private CacheConfiguration cacheConfiguration(String cacheName) {
-        CacheConfiguration cfg = new CacheConfiguration();
-
-        cfg.setName(cacheName);
-
-        cfg.setCacheMode(PARTITIONED);
-
-        cfg.setAtomicityMode(ATOMIC);
-
-        return cfg;
-    }
-    /**
-     * @param igniteInstanceName Ignite instance name.
-     * @return Hibernate configuration.
-     */
-    protected Configuration hibernateConfiguration(String igniteInstanceName) {
-        Configuration cfg = new Configuration();
-
-        cfg.addAnnotatedClass(Entity1.class);
-        cfg.addAnnotatedClass(Entity2.class);
-        cfg.addAnnotatedClass(Entity3.class);
-        cfg.addAnnotatedClass(Entity4.class);
-
-        cfg.setProperty(DFLT_ACCESS_TYPE_PROPERTY, AccessType.NONSTRICT_READ_WRITE.name());
-
-        cfg.setProperty(HBM2DDL_AUTO, "create");
-
-        cfg.setProperty(GENERATE_STATISTICS, "true");
-
-        cfg.setProperty(USE_SECOND_LEVEL_CACHE, "true");
-
-        cfg.setProperty(USE_QUERY_CACHE, "true");
-
-        cfg.setProperty(CACHE_REGION_FACTORY, HibernateRegionFactory.class.getName());
-
-        cfg.setProperty(RELEASE_CONNECTIONS, "on_close");
-
-        cfg.setProperty(IGNITE_INSTANCE_NAME_PROPERTY, igniteInstanceName);
-
-        cfg.setProperty(REGION_CACHE_PROPERTY + ENTITY1_NAME, "cache1");
-        cfg.setProperty(REGION_CACHE_PROPERTY + ENTITY2_NAME, "cache2");
-        cfg.setProperty(REGION_CACHE_PROPERTY + TIMESTAMP_CACHE, TIMESTAMP_CACHE);
-        cfg.setProperty(REGION_CACHE_PROPERTY + QUERY_CACHE, QUERY_CACHE);
-
-        if (dfltCache)
-            cfg.setProperty(DFLT_CACHE_NAME_PROPERTY, "cache3");
-
-        return cfg;
-    }
-
-    /**
-     * Tests property {@link HibernateRegionFactory#REGION_CACHE_PROPERTY}.
-     */
-    public void testPerRegionCacheProperty() {
-        testCacheUsage(1, 1, 0, 1, 1);
-    }
-
-    /**
-     * Tests property {@link HibernateRegionFactory#DFLT_CACHE_NAME_PROPERTY}.
-     */
-    public void testDefaultCache() {
-        dfltCache = true;
-
-        testCacheUsage(1, 1, 2, 0, 0);
-    }
-
-    /**
-     * @param expCache1 Expected size of cache with name 'cache1'.
-     * @param expCache2 Expected size of cache with name 'cache2'.
-     * @param expCache3 Expected size of cache with name 'cache3'.
-     * @param expCacheE3 Expected size of cache with name {@link #ENTITY3_NAME}.
-     * @param expCacheE4 Expected size of cache with name {@link #ENTITY4_NAME}.
-     */
-    @SuppressWarnings("unchecked")
-    private void testCacheUsage(int expCache1, int expCache2, int expCache3, int expCacheE3, int expCacheE4) {
-        SessionFactory sesFactory = startHibernate(getTestIgniteInstanceName(0));
-
-        try {
-            Session ses = sesFactory.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                ses.save(new Entity1());
-                ses.save(new Entity2());
-                ses.save(new Entity3());
-                ses.save(new Entity4());
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            ses = sesFactory.openSession();
-
-            try {
-                List<Entity1> list1 = ses.createCriteria(ENTITY1_NAME).list();
-
-                assertEquals(1, list1.size());
-
-                for (Entity1 e : list1) {
-                    ses.load(ENTITY1_NAME, e.getId());
-                    assertNotNull(e.getId());
-                }
-
-                List<Entity2> list2 = ses.createCriteria(ENTITY2_NAME).list();
-
-                assertEquals(1, list2.size());
-
-                for (Entity2 e : list2)
-                    assertNotNull(e.getId());
-
-                List<Entity3> list3 = ses.createCriteria(ENTITY3_NAME).list();
-
-                assertEquals(1, list3.size());
-
-                for (Entity3 e : list3)
-                    assertNotNull(e.getId());
-
-                List<Entity4> list4 = ses.createCriteria(ENTITY4_NAME).list();
-
-                assertEquals(1, list4.size());
-
-                for (Entity4 e : list4)
-                    assertNotNull(e.getId());
-            }
-            finally {
-                ses.close();
-            }
-
-            IgniteCache<Object, Object> cache1 = grid(0).cache("cache1");
-            IgniteCache<Object, Object> cache2 = grid(0).cache("cache2");
-            IgniteCache<Object, Object> cache3 = grid(0).cache("cache3");
-            IgniteCache<Object, Object> cacheE3 = grid(0).cache(ENTITY3_NAME);
-            IgniteCache<Object, Object> cacheE4 = grid(0).cache(ENTITY4_NAME);
-
-            assertEquals("Unexpected entries: " + toSet(cache1.iterator()), expCache1, cache1.size());
-            assertEquals("Unexpected entries: " + toSet(cache2.iterator()), expCache2, cache2.size());
-            assertEquals("Unexpected entries: " + toSet(cache3.iterator()), expCache3, cache3.size());
-            assertEquals("Unexpected entries: " + toSet(cacheE3.iterator()), expCacheE3, cacheE3.size());
-            assertEquals("Unexpected entries: " + toSet(cacheE4.iterator()), expCacheE4, cacheE4.size());
-        }
-        finally {
-            sesFactory.close();
-        }
-    }
-
-    /**
-     *
-     */
-    private <K, V> Set<Cache.Entry<K, V>> toSet(Iterator<Cache.Entry<K, V>> iter){
-        Set<Cache.Entry<K, V>> set = new HashSet<>();
-
-        while (iter.hasNext())
-            set.add(iter.next());
-
-        return set;
-    }
-
-    /**
-     * @param igniteInstanceName Name of the grid providing caches.
-     * @return Session factory.
-     */
-    private SessionFactory startHibernate(String igniteInstanceName) {
-        Configuration cfg = hibernateConfiguration(igniteInstanceName);
-
-        ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
-
-        builder.applySetting("hibernate.connection.url", CONNECTION_URL);
-        builder.applySetting("hibernate.show_sql", false);
-
-        return cfg.buildSessionFactory(builder.buildServiceRegistry());
-    }
-
-    /**
-     * Test Hibernate entity1.
-     */
-    @javax.persistence.Entity
-    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
-    @Cacheable
-    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
-    public static class Entity1 {
-        /** */
-        private int id;
-
-        /**
-         * @return ID.
-         */
-        @Id
-        @GeneratedValue
-        public int getId() {
-            return id;
-        }
-
-        /**
-         * @param id ID.
-         */
-        public void setId(int id) {
-            this.id = id;
-        }
-    }
-
-    /**
-     * Test Hibernate entity2.
-     */
-    @javax.persistence.Entity
-    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
-    @Cacheable
-    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
-    public static class Entity2 {
-        /** */
-        private int id;
-
-        /**
-         * @return ID.
-         */
-        @Id
-        @GeneratedValue
-        public int getId() {
-            return id;
-        }
-
-        /**
-         * @param id ID.
-         */
-        public void setId(int id) {
-            this.id = id;
-        }
-    }
-
-    /**
-     * Test Hibernate entity3.
-     */
-    @javax.persistence.Entity
-    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
-    @Cacheable
-    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
-    public static class Entity3 {
-        /** */
-        private int id;
-
-        /**
-         * @return ID.
-         */
-        @Id
-        @GeneratedValue
-        public int getId() {
-            return id;
-        }
-
-        /**
-         * @param id ID.
-         */
-        public void setId(int id) {
-            this.id = id;
-        }
-    }
-
-    /**
-     * Test Hibernate entity4.
-     */
-    @javax.persistence.Entity
-    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
-    @Cacheable
-    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
-    public static class Entity4 {
-        /** */
-        private int id;
-
-        /**
-         * @return ID.
-         */
-        @Id
-        @GeneratedValue
-        public int getId() {
-            return id;
-        }
-
-        /**
-         * @param id ID.
-         */
-        public void setId(int id) {
-            this.id = id;
-        }
-    }
-}
\ No newline at end of file


[06/16] ignite git commit: ignite-1794 Refactored hibernate modules, switched to hibernate 5.1

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java b/modules/hibernate/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java
deleted file mode 100644
index 13956dc..0000000
--- a/modules/hibernate/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java
+++ /dev/null
@@ -1,1949 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.Callable;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.OneToMany;
-import javax.persistence.OneToOne;
-import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.hibernate.ObjectNotFoundException;
-import org.hibernate.Query;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.StaleObjectStateException;
-import org.hibernate.Transaction;
-import org.hibernate.annotations.NaturalId;
-import org.hibernate.annotations.NaturalIdCache;
-import org.hibernate.cache.spi.GeneralDataRegion;
-import org.hibernate.cache.spi.TransactionalDataRegion;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.exception.ConstraintViolationException;
-import org.hibernate.service.ServiceRegistryBuilder;
-import org.hibernate.stat.NaturalIdCacheStatistics;
-import org.hibernate.stat.SecondLevelCacheStatistics;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
-import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
-import static org.apache.ignite.cache.hibernate.HibernateRegionFactory.DFLT_ACCESS_TYPE_PROPERTY;
-import static org.apache.ignite.cache.hibernate.HibernateRegionFactory.IGNITE_INSTANCE_NAME_PROPERTY;
-import static org.apache.ignite.cache.hibernate.HibernateRegionFactory.REGION_CACHE_PROPERTY;
-import static org.hibernate.cfg.Environment.CACHE_REGION_FACTORY;
-import static org.hibernate.cfg.Environment.GENERATE_STATISTICS;
-import static org.hibernate.cfg.Environment.HBM2DDL_AUTO;
-import static org.hibernate.cfg.Environment.RELEASE_CONNECTIONS;
-import static org.hibernate.cfg.Environment.USE_QUERY_CACHE;
-import static org.hibernate.cfg.Environment.USE_SECOND_LEVEL_CACHE;
-
-/**
- *
- * Tests Hibernate L2 cache.
- */
-public class HibernateL2CacheSelfTest extends GridCommonAbstractTest {
-    /** */
-    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
-
-    /** */
-    public static final String CONNECTION_URL = "jdbc:h2:mem:example;DB_CLOSE_DELAY=-1";
-
-    /** */
-    public static final String ENTITY_NAME = Entity.class.getName();
-
-    /** */
-    public static final String ENTITY2_NAME = Entity2.class.getName();
-
-    /** */
-    public static final String VERSIONED_ENTITY_NAME = VersionedEntity.class.getName();
-
-    /** */
-    public static final String PARENT_ENTITY_NAME = ParentEntity.class.getName();
-
-    /** */
-    public static final String CHILD_COLLECTION_REGION = ENTITY_NAME + ".children";
-
-    /** */
-    public static final String NATURAL_ID_REGION =
-        "org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest$Entity##NaturalId";
-
-    /** */
-    public static final String NATURAL_ID_REGION2 =
-        "org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest$Entity2##NaturalId";
-
-    /** */
-    private SessionFactory sesFactory1;
-
-    /** */
-    private SessionFactory sesFactory2;
-
-    /**
-     * First Hibernate test entity.
-     */
-    @javax.persistence.Entity
-    @NaturalIdCache
-    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
-    public static class Entity {
-        /** */
-        private int id;
-
-        /** */
-        private String name;
-
-        /** */
-        private Collection<ChildEntity> children;
-
-        /**
-         * Default constructor required by Hibernate.
-         */
-        public Entity() {
-            // No-op.
-        }
-
-        /**
-         * @param id ID.
-         * @param name Name.
-         */
-        public Entity(int id, String name) {
-            this.id = id;
-            this.name = name;
-        }
-
-        /**
-         * @return ID.
-         */
-        @Id
-        public int getId() {
-            return id;
-        }
-
-        /**
-         * @param id ID.
-         */
-        public void setId(int id) {
-            this.id = id;
-        }
-
-        /**
-         * @return Name.
-         */
-        @NaturalId(mutable = true)
-        public String getName() {
-            return name;
-        }
-
-        /**
-         * @param name Name.
-         */
-        public void setName(String name) {
-            this.name = name;
-        }
-
-        /**
-         * @return Children.
-         */
-        @OneToMany(cascade=javax.persistence.CascadeType.ALL, fetch=FetchType.LAZY)
-        @JoinColumn(name="ENTITY_ID")
-        public Collection<ChildEntity> getChildren() {
-            return children;
-        }
-
-        /**
-         * @param children Children.
-         */
-        public void setChildren(Collection<ChildEntity> children) {
-            this.children = children;
-        }
-    }
-
-    /**
-     * Second Hibernate test entity.
-     */
-    @javax.persistence.Entity
-    @NaturalIdCache
-    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
-    public static class Entity2 {
-        /** */
-        private int id;
-
-        /** */
-        private String name;
-
-        /** */
-        private Collection<ChildEntity> children;
-
-        /**
-         * Default constructor required by Hibernate.
-         */
-        public Entity2() {
-            // No-op.
-        }
-
-        /**
-         * @param id ID.
-         * @param name Name.
-         */
-        public Entity2(int id, String name) {
-            this.id = id;
-            this.name = name;
-        }
-
-        /**
-         * @return ID.
-         */
-        @Id
-        public int getId() {
-            return id;
-        }
-
-        /**
-         * @param id ID.
-         */
-        public void setId(int id) {
-            this.id = id;
-        }
-
-        /**
-         * @return Name.
-         */
-        @NaturalId(mutable = true)
-        public String getName() {
-            return name;
-        }
-
-        /**
-         * @param name Name.
-         */
-        public void setName(String name) {
-            this.name = name;
-        }
-    }
-
-    /**
-     * Hibernate child entity referenced by {@link Entity}.
-     */
-    @javax.persistence.Entity
-    @SuppressWarnings("PublicInnerClass")
-    public static class ChildEntity {
-        /** */
-        private int id;
-
-        /**
-         * Default constructor required by Hibernate.
-         */
-        public ChildEntity() {
-            // No-op.
-        }
-
-        /**
-         * @param id ID.
-         */
-        public ChildEntity(int id) {
-            this.id = id;
-        }
-
-        /**
-         * @return ID.
-         */
-        @Id
-        @GeneratedValue
-        public int getId() {
-            return id;
-        }
-
-        /**
-         * @param id ID.
-         */
-        public void setId(int id) {
-            this.id = id;
-        }
-    }
-
-    /**
-     * Hibernate entity referencing {@link Entity}.
-     */
-    @javax.persistence.Entity
-    @SuppressWarnings("PublicInnerClass")
-    public static class ParentEntity {
-        /** */
-        private int id;
-
-        /** */
-        private Entity entity;
-
-        /**
-         * Default constructor required by Hibernate.
-         */
-        public ParentEntity() {
-            // No-op.
-        }
-
-        /**
-         * @param id ID.
-         * @param entity Referenced entity.
-         */
-        public ParentEntity(int id, Entity entity) {
-            this.id = id;
-            this.entity = entity;
-        }
-
-        /**
-         * @return ID.
-         */
-        @Id
-        public int getId() {
-            return id;
-        }
-
-        /**
-         * @param id ID.
-         */
-        public void setId(int id) {
-            this.id = id;
-        }
-
-        /**
-         * @return Referenced entity.
-         */
-        @OneToOne
-        public Entity getEntity() {
-            return entity;
-        }
-
-        /**
-         * @param entity Referenced entity.
-         */
-        public void setEntity(Entity entity) {
-            this.entity = entity;
-        }
-    }
-
-    /**
-     * Hibernate entity.
-     */
-    @javax.persistence.Entity
-    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
-    public static class VersionedEntity {
-        /** */
-        private int id;
-
-        /** */
-        private long ver;
-
-        /**
-         * Default constructor required by Hibernate.
-         */
-        public VersionedEntity() {
-        }
-
-        /**
-         * @param id ID.
-         */
-        public VersionedEntity(int id) {
-            this.id = id;
-        }
-
-        /**
-         * @return ID.
-         */
-        @Id
-        public int getId() {
-            return id;
-        }
-
-        /**
-         * @param id ID.
-         */
-        public void setId(int id) {
-            this.id = id;
-        }
-
-        /**
-         * @return Version.
-         */
-        @javax.persistence.Version
-        public long getVersion() {
-            return ver;
-        }
-
-        /**
-         * @param ver Version.
-         */
-        public void setVersion(long ver) {
-            this.ver = ver;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
-
-        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
-
-        discoSpi.setIpFinder(IP_FINDER);
-
-        cfg.setDiscoverySpi(discoSpi);
-
-        cfg.setCacheConfiguration(generalRegionConfiguration("org.hibernate.cache.spi.UpdateTimestampsCache"),
-            generalRegionConfiguration("org.hibernate.cache.internal.StandardQueryCache"),
-            transactionalRegionConfiguration(ENTITY_NAME),
-            transactionalRegionConfiguration(ENTITY2_NAME),
-            transactionalRegionConfiguration(VERSIONED_ENTITY_NAME),
-            transactionalRegionConfiguration(PARENT_ENTITY_NAME),
-            transactionalRegionConfiguration(CHILD_COLLECTION_REGION),
-            transactionalRegionConfiguration(NATURAL_ID_REGION),
-            transactionalRegionConfiguration(NATURAL_ID_REGION2));
-
-        return cfg;
-    }
-
-    /**
-     * @param regionName Region name.
-     * @return Cache configuration for {@link GeneralDataRegion}.
-     */
-    private CacheConfiguration generalRegionConfiguration(String regionName) {
-        CacheConfiguration cfg = new CacheConfiguration();
-
-        cfg.setName(regionName);
-
-        cfg.setCacheMode(PARTITIONED);
-
-        cfg.setAtomicityMode(ATOMIC);
-
-        cfg.setWriteSynchronizationMode(FULL_SYNC);
-
-        cfg.setBackups(1);
-
-        cfg.setAffinity(new RendezvousAffinityFunction(false, 10));
-
-        return cfg;
-    }
-
-    /**
-     * @param regionName Region name.
-     * @return Cache configuration for {@link TransactionalDataRegion}.
-     */
-    protected CacheConfiguration transactionalRegionConfiguration(String regionName) {
-        CacheConfiguration cfg = new CacheConfiguration();
-
-        cfg.setName(regionName);
-
-        cfg.setCacheMode(PARTITIONED);
-
-        cfg.setAtomicityMode(TRANSACTIONAL);
-
-        cfg.setWriteSynchronizationMode(FULL_SYNC);
-
-        cfg.setBackups(1);
-
-        cfg.setAffinity(new RendezvousAffinityFunction(false, 10));
-
-        return cfg;
-    }
-
-    /**
-     * @param accessType Hibernate L2 cache access type.
-     * @param igniteInstanceName Ignite instance name.
-     * @return Hibernate configuration.
-     */
-    private Configuration hibernateConfiguration(AccessType accessType,
-        String igniteInstanceName) {
-        Configuration cfg = new Configuration();
-
-        cfg.addAnnotatedClass(Entity.class);
-        cfg.addAnnotatedClass(Entity2.class);
-        cfg.addAnnotatedClass(VersionedEntity.class);
-        cfg.addAnnotatedClass(ChildEntity.class);
-        cfg.addAnnotatedClass(ParentEntity.class);
-
-        cfg.setCacheConcurrencyStrategy(ENTITY_NAME, accessType.getExternalName());
-        cfg.setCacheConcurrencyStrategy(ENTITY2_NAME, accessType.getExternalName());
-        cfg.setCacheConcurrencyStrategy(VERSIONED_ENTITY_NAME, accessType.getExternalName());
-        cfg.setCacheConcurrencyStrategy(PARENT_ENTITY_NAME, accessType.getExternalName());
-        cfg.setCollectionCacheConcurrencyStrategy(CHILD_COLLECTION_REGION, accessType.getExternalName());
-
-        cfg.setProperty(HBM2DDL_AUTO, "create");
-
-        cfg.setProperty(GENERATE_STATISTICS, "true");
-
-        cfg.setProperty(USE_SECOND_LEVEL_CACHE, "true");
-
-        cfg.setProperty(USE_QUERY_CACHE, "true");
-
-        cfg.setProperty(CACHE_REGION_FACTORY, HibernateRegionFactory.class.getName());
-
-        cfg.setProperty(RELEASE_CONNECTIONS, "on_close");
-
-        cfg.setProperty(IGNITE_INSTANCE_NAME_PROPERTY, igniteInstanceName);
-
-        // Use the same cache for Entity and Entity2.
-        cfg.setProperty(REGION_CACHE_PROPERTY + ENTITY2_NAME, ENTITY_NAME);
-
-        cfg.setProperty(DFLT_ACCESS_TYPE_PROPERTY, accessType.name());
-
-        return cfg;
-    }
-
-    /**
-     * @return Hibernate registry builder.
-     */
-    protected ServiceRegistryBuilder registryBuilder() {
-        ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
-
-        builder.applySetting("hibernate.connection.url", CONNECTION_URL);
-
-        return builder;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        startGrids(2);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        stopAllGrids();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        cleanup();
-    }
-
-    /**
-     * @return Hibernate L2 cache access types to test.
-     */
-    protected AccessType[] accessTypes() {
-        return new AccessType[]{AccessType.READ_ONLY, AccessType.NONSTRICT_READ_WRITE, AccessType.READ_WRITE};
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testCollectionCache() throws Exception {
-        for (AccessType accessType : accessTypes())
-            testCollectionCache(accessType);
-    }
-
-    /**
-     * @param accessType Cache access type.
-     * @throws Exception If failed.
-     */
-    @SuppressWarnings("unchecked")
-    private void testCollectionCache(AccessType accessType) throws Exception {
-        createSessionFactories(accessType);
-
-        Map<Integer, Integer> idToChildCnt = new HashMap<>();
-
-        try {
-            Session ses = sesFactory1.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                for (int i = 0; i < 3; i++) {
-                    Entity e = new Entity(i, "name-" + i);
-
-                    Collection<ChildEntity> children = new ArrayList<>();
-
-                    for (int j = 0; j < 3; j++)
-                        children.add(new ChildEntity());
-
-                    e.setChildren(children);
-
-                    idToChildCnt.put(e.getId(), e.getChildren().size());
-
-                    ses.save(e);
-                }
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            // Load children, this should populate cache.
-
-            ses = sesFactory1.openSession();
-
-            try {
-                List<Entity> list = ses.createCriteria(ENTITY_NAME).list();
-
-                assertEquals(idToChildCnt.size(), list.size());
-
-                for (Entity e : list)
-                    assertEquals((int)idToChildCnt.get(e.getId()), e.getChildren().size());
-            }
-            finally {
-                ses.close();
-            }
-
-            assertCollectionCache(sesFactory2, idToChildCnt, 3, 0);
-            assertCollectionCache(sesFactory1, idToChildCnt, 3, 0);
-
-            if (accessType == AccessType.READ_ONLY)
-                return;
-
-            // Update children for one entity.
-
-            ses = sesFactory1.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                Entity e1 = (Entity)ses.load(Entity.class, 1);
-
-                e1.getChildren().remove(e1.getChildren().iterator().next());
-
-                ses.update(e1);
-
-                idToChildCnt.put(e1.getId(), e1.getChildren().size());
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertCollectionCache(sesFactory2, idToChildCnt, 2, 1); // After update collection cache entry is removed.
-            assertCollectionCache(sesFactory1, idToChildCnt, 3, 0); // 'assertCollectionCache' loads children in cache.
-
-            // Update children for the same entity using another SessionFactory.
-
-            ses = sesFactory2.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                Entity e1 = (Entity)ses.load(Entity.class, 1);
-
-                e1.getChildren().remove(e1.getChildren().iterator().next());
-
-                ses.update(e1);
-
-                idToChildCnt.put(e1.getId(), e1.getChildren().size());
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertCollectionCache(sesFactory2, idToChildCnt, 2, 1); // After update collection cache entry is removed.
-            assertCollectionCache(sesFactory1, idToChildCnt, 3, 0); // 'assertCollectionCache' loads children in cache.
-        }
-        finally {
-            cleanup();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testEntityCache() throws Exception {
-        for (AccessType accessType : accessTypes())
-            testEntityCache(accessType);
-    }
-
-    /**
-     * @param accessType Cache access type.
-     * @throws Exception If failed.
-     */
-    private void testEntityCache(AccessType accessType) throws Exception {
-        createSessionFactories(accessType);
-
-        Map<Integer, String> idToName = new HashMap<>();
-
-        try {
-            Session ses = sesFactory1.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                for (int i = 0; i < 2; i++) {
-                    String name = "name-" + i;
-
-                    ses.save(new Entity(i, name));
-
-                    idToName.put(i, name);
-                }
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName, 100);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName, 100);
-
-            if (accessType == AccessType.READ_ONLY)
-                return;
-
-            ses = sesFactory1.openSession();
-
-            try {
-                // Updates and inserts in single transaction.
-
-                Transaction tx = ses.beginTransaction();
-
-                Entity e0 = (Entity)ses.load(Entity.class, 0);
-
-                e0.setName("name-0-changed1");
-
-                ses.update(e0);
-
-                idToName.put(0, e0.getName());
-
-                ses.save(new Entity(2, "name-2"));
-
-                idToName.put(2, "name-2");
-
-                Entity e1 = (Entity)ses.load(Entity.class, 1);
-
-                e1.setName("name-1-changed1");
-
-                ses.update(e1);
-
-                idToName.put(1, e1.getName());
-
-                ses.save(new Entity(3, "name-3"));
-
-                idToName.put(3, "name-3");
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName);
-
-            ses = sesFactory1.openSession();
-
-            try {
-                // Updates, inserts and deletes in single transaction.
-
-                Transaction tx = ses.beginTransaction();
-
-                ses.save(new Entity(4, "name-4"));
-
-                idToName.put(4, "name-4");
-
-                Entity e0 = (Entity)ses.load(Entity.class, 0);
-
-                e0.setName("name-0-changed2");
-
-                ses.update(e0);
-
-                idToName.put(e0.getId(), e0.getName());
-
-                ses.delete(ses.load(Entity.class, 1));
-
-                idToName.remove(1);
-
-                Entity e2 = (Entity)ses.load(Entity.class, 2);
-
-                e2.setName("name-2-changed1");
-
-                ses.update(e2);
-
-                idToName.put(e2.getId(), e2.getName());
-
-                ses.delete(ses.load(Entity.class, 3));
-
-                idToName.remove(3);
-
-                ses.save(new Entity(5, "name-5"));
-
-                idToName.put(5, "name-5");
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName, 1, 3);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName, 1, 3);
-
-            // Try to update the same entity using another SessionFactory.
-
-            ses = sesFactory2.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                Entity e0 = (Entity)ses.load(Entity.class, 0);
-
-                e0.setName("name-0-changed3");
-
-                ses.update(e0);
-
-                idToName.put(e0.getId(), e0.getName());
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName);
-        }
-        finally {
-            cleanup();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testTwoEntitiesSameCache() throws Exception {
-        for (AccessType accessType : accessTypes())
-            testTwoEntitiesSameCache(accessType);
-    }
-
-    /**
-     * @param accessType Cache access type.
-     * @throws Exception If failed.
-     */
-    private void testTwoEntitiesSameCache(AccessType accessType) throws Exception {
-        createSessionFactories(accessType);
-
-        try {
-            Session ses = sesFactory1.openSession();
-
-            Map<Integer, String> idToName1 = new HashMap<>();
-            Map<Integer, String> idToName2 = new HashMap<>();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                for (int i = 0; i < 2; i++) {
-                    String name = "name-" + i;
-
-                    ses.save(new Entity(i, name));
-                    ses.save(new Entity2(i, name));
-
-                    idToName1.put(i, name);
-                    idToName2.put(i, name);
-                }
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName1, 100);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName1, 100);
-
-            assertEntityCache(ENTITY2_NAME, sesFactory2, idToName2, 100);
-            assertEntityCache(ENTITY2_NAME, sesFactory1, idToName2, 100);
-
-            if (accessType == AccessType.READ_ONLY)
-                return;
-
-            ses = sesFactory1.openSession();
-
-            try {
-                // Updates both entities in single transaction.
-
-                Transaction tx = ses.beginTransaction();
-
-                Entity e = (Entity)ses.load(Entity.class, 0);
-
-                e.setName("name-0-changed1");
-
-                ses.update(e);
-
-                Entity2 e2 = (Entity2)ses.load(Entity2.class, 0);
-
-                e2.setName("name-e2-0-changed1");
-
-                ses.update(e2);
-
-                idToName1.put(0, e.getName());
-                idToName2.put(0, e2.getName());
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName1, 100);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName1, 100);
-
-            assertEntityCache(ENTITY2_NAME, sesFactory2, idToName2, 100);
-            assertEntityCache(ENTITY2_NAME, sesFactory1, idToName2, 100);
-
-            ses = sesFactory1.openSession();
-
-            try {
-                // Remove entity1 and insert entity2 in single transaction.
-
-                Transaction tx = ses.beginTransaction();
-
-                Entity e = (Entity)ses.load(Entity.class, 0);
-
-                ses.delete(e);
-
-                Entity2 e2 = new Entity2(2, "name-2");
-
-                ses.save(e2);
-
-                idToName1.remove(0);
-                idToName2.put(2, e2.getName());
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName1, 0, 100);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName1, 0, 100);
-
-            assertEntityCache(ENTITY2_NAME, sesFactory2, idToName2, 100);
-            assertEntityCache(ENTITY2_NAME, sesFactory1, idToName2, 100);
-
-            ses = sesFactory1.openSession();
-
-            Transaction tx = ses.beginTransaction();
-
-            try {
-                // Update, remove, insert in single transaction, transaction fails.
-
-                Entity e = (Entity)ses.load(Entity.class, 1);
-
-                e.setName("name-1-changed1");
-
-                ses.update(e); // Valid update.
-
-                ses.save(new Entity(2, "name-2")); // Valid insert.
-
-                ses.delete(ses.load(Entity2.class, 0)); // Valid delete.
-
-                Entity2 e2 = (Entity2)ses.load(Entity2.class, 1);
-
-                e2.setName("name-2");  // Invalid update, not-unique name.
-
-                ses.update(e2);
-
-                tx.commit();
-
-                fail("Commit must fail.");
-            }
-            catch (ConstraintViolationException e) {
-                log.info("Expected exception: " + e);
-
-                tx.rollback();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName1, 0, 2, 100);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName1, 0, 2, 100);
-
-            assertEntityCache(ENTITY2_NAME, sesFactory2, idToName2, 100);
-            assertEntityCache(ENTITY2_NAME, sesFactory1, idToName2, 100);
-
-            ses = sesFactory2.openSession();
-
-            try {
-                // Update, remove, insert in single transaction.
-
-                tx = ses.beginTransaction();
-
-                Entity e = (Entity)ses.load(Entity.class, 1);
-
-                e.setName("name-1-changed1");
-
-                ses.update(e);
-
-                idToName1.put(1, e.getName());
-
-                ses.save(new Entity(2, "name-2"));
-
-                idToName1.put(2, "name-2");
-
-                ses.delete(ses.load(Entity2.class, 0));
-
-                idToName2.remove(0);
-
-                Entity2 e2 = (Entity2)ses.load(Entity2.class, 1);
-
-                e2.setName("name-e2-2-changed");
-
-                ses.update(e2);
-
-                idToName2.put(1, e2.getName());
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName1, 0, 100);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName1, 0, 100);
-
-            assertEntityCache(ENTITY2_NAME, sesFactory2, idToName2, 0, 100);
-            assertEntityCache(ENTITY2_NAME, sesFactory1, idToName2, 0, 100);
-        }
-        finally {
-            cleanup();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testVersionedEntity() throws Exception {
-        for (AccessType accessType : accessTypes())
-            testVersionedEntity(accessType);
-    }
-
-    /**
-     * @param accessType Cache access type.
-     * @throws Exception If failed.
-     */
-    private void testVersionedEntity(AccessType accessType) throws Exception {
-        createSessionFactories(accessType);
-
-        try {
-            Session ses = sesFactory1.openSession();
-
-            VersionedEntity e0 = new VersionedEntity(0);
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                ses.save(e0);
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            ses = sesFactory1.openSession();
-
-            long ver;
-
-            try {
-                ver = ((VersionedEntity)ses.load(VersionedEntity.class, 0)).getVersion();
-            }
-            finally {
-                ses.close();
-            }
-
-            SecondLevelCacheStatistics stats1 =
-                sesFactory1.getStatistics().getSecondLevelCacheStatistics(VERSIONED_ENTITY_NAME);
-            SecondLevelCacheStatistics stats2 =
-                sesFactory2.getStatistics().getSecondLevelCacheStatistics(VERSIONED_ENTITY_NAME);
-
-            assertEquals(1, stats1.getElementCountInMemory());
-            assertEquals(1, stats2.getElementCountInMemory());
-
-            ses = sesFactory2.openSession();
-
-            try {
-                assertEquals(ver, ((VersionedEntity)ses.load(VersionedEntity.class, 0)).getVersion());
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEquals(1, stats2.getElementCountInMemory());
-            assertEquals(1, stats2.getHitCount());
-
-            if (accessType == AccessType.READ_ONLY)
-                return;
-
-            e0.setVersion(ver - 1);
-
-            ses = sesFactory1.openSession();
-
-            Transaction tx = ses.beginTransaction();
-
-            try {
-                ses.update(e0);
-
-                tx.commit();
-
-                fail("Commit must fail.");
-            }
-            catch (StaleObjectStateException e) {
-                log.info("Expected exception: " + e);
-            }
-            finally {
-                tx.rollback();
-
-                ses.close();
-            }
-
-            sesFactory1.getStatistics().clear();
-
-            stats1 = sesFactory1.getStatistics().getSecondLevelCacheStatistics(VERSIONED_ENTITY_NAME);
-
-            ses = sesFactory1.openSession();
-
-            try {
-                assertEquals(ver, ((VersionedEntity)ses.load(VersionedEntity.class, 0)).getVersion());
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEquals(1, stats1.getElementCountInMemory());
-            assertEquals(1, stats1.getHitCount());
-            assertEquals(1, stats2.getElementCountInMemory());
-            assertEquals(1, stats2.getHitCount());
-        }
-        finally {
-            cleanup();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testNaturalIdCache() throws Exception {
-        fail("https://issues.apache.org/jira/browse/IGNITE-1084");
-
-        for (AccessType accessType : accessTypes())
-            testNaturalIdCache(accessType);
-    }
-
-    /**
-     * @param accessType Cache access type.
-     * @throws Exception If failed.
-     */
-    private void testNaturalIdCache(AccessType accessType) throws Exception {
-        createSessionFactories(accessType);
-
-        Map<String, Integer> nameToId = new HashMap<>();
-
-        try {
-            Session ses = sesFactory1.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                for (int i = 0; i < 3; i++) {
-                    String name = "name-" + i;
-
-                    ses.save(new Entity(i, name));
-
-                    nameToId.put(name, i);
-                }
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            ses = sesFactory1.openSession();
-
-            try {
-                for (Map.Entry<String, Integer> e : nameToId.entrySet())
-                    ((Entity)ses.bySimpleNaturalId(Entity.class).load(e.getKey())).getId();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertNaturalIdCache(sesFactory2, nameToId, "name-100");
-            assertNaturalIdCache(sesFactory1, nameToId, "name-100");
-
-            if (accessType == AccessType.READ_ONLY)
-                return;
-
-            // Update naturalId.
-
-            ses = sesFactory1.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                Entity e1 = (Entity)ses.load(Entity.class, 1);
-
-                nameToId.remove(e1.getName());
-
-                e1.setName("name-1-changed1");
-
-                nameToId.put(e1.getName(), e1.getId());
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertNaturalIdCache(sesFactory2, nameToId, "name-1");
-            assertNaturalIdCache(sesFactory1, nameToId, "name-1");
-
-            // Update entity using another SessionFactory.
-
-            ses = sesFactory2.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                Entity e1 = (Entity)ses.load(Entity.class, 1);
-
-                nameToId.remove(e1.getName());
-
-                e1.setName("name-1-changed2");
-
-                nameToId.put(e1.getName(), e1.getId());
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertNaturalIdCache(sesFactory2, nameToId, "name-1-changed1");
-            assertNaturalIdCache(sesFactory1, nameToId, "name-1-changed1");
-
-            // Try invalid NaturalId update.
-
-            ses = sesFactory1.openSession();
-
-            Transaction tx = ses.beginTransaction();
-
-            try {
-                Entity e1 = (Entity)ses.load(Entity.class, 1);
-
-                e1.setName("name-0"); // Invalid update (duplicated name).
-
-                tx.commit();
-
-                fail("Commit must fail.");
-            }
-            catch (ConstraintViolationException e) {
-                log.info("Expected exception: " + e);
-
-                tx.rollback();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertNaturalIdCache(sesFactory2, nameToId);
-            assertNaturalIdCache(sesFactory1, nameToId);
-
-            // Delete entity.
-
-            ses = sesFactory2.openSession();
-
-            try {
-                tx = ses.beginTransaction();
-
-                Entity e2 = (Entity)ses.load(Entity.class, 2);
-
-                ses.delete(e2);
-
-                nameToId.remove(e2.getName());
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertNaturalIdCache(sesFactory2, nameToId, "name-2");
-            assertNaturalIdCache(sesFactory1, nameToId, "name-2");
-        }
-        finally {
-            cleanup();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testEntityCacheTransactionFails() throws Exception {
-        for (AccessType accessType : accessTypes())
-            testEntityCacheTransactionFails(accessType);
-    }
-
-    /**
-     * @param accessType Cache access type.
-     * @throws Exception If failed.
-     */
-    private void testEntityCacheTransactionFails(AccessType accessType) throws Exception {
-        createSessionFactories(accessType);
-
-        Map<Integer, String> idToName = new HashMap<>();
-
-        try {
-            Session ses = sesFactory1.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                for (int i = 0; i < 3; i++) {
-                    String name = "name-" + i;
-
-                    ses.save(new Entity(i, name));
-
-                    idToName.put(i, name);
-                }
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName, 100);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName, 100);
-
-            ses = sesFactory1.openSession();
-
-            Transaction tx = ses.beginTransaction();
-
-            try {
-                ses.save(new Entity(3, "name-3")); // Valid insert.
-
-                ses.save(new Entity(0, "name-0")); // Invalid insert (duplicated ID).
-
-                tx.commit();
-
-                fail("Commit must fail.");
-            }
-            catch (ConstraintViolationException e) {
-                log.info("Expected exception: " + e);
-
-                tx.rollback();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName, 3);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName, 3);
-
-            if (accessType == AccessType.READ_ONLY)
-                return;
-
-            ses = sesFactory1.openSession();
-
-            tx = ses.beginTransaction();
-
-            try {
-                Entity e0 = (Entity)ses.load(Entity.class, 0);
-                Entity e1 = (Entity)ses.load(Entity.class, 1);
-
-                e0.setName("name-10"); // Valid update.
-                e1.setName("name-2"); // Invalid update (violates unique constraint).
-
-                ses.update(e0);
-                ses.update(e1);
-
-                tx.commit();
-
-                fail("Commit must fail.");
-            }
-            catch (ConstraintViolationException e) {
-                log.info("Expected exception: " + e);
-
-                tx.rollback();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName);
-
-            ses = sesFactory1.openSession();
-
-            try {
-                // Create parent entity referencing Entity with ID = 0.
-
-                tx = ses.beginTransaction();
-
-                ses.save(new ParentEntity(0, (Entity) ses.load(Entity.class, 0)));
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            ses = sesFactory1.openSession();
-
-            tx = ses.beginTransaction();
-
-            try {
-                ses.save(new Entity(3, "name-3")); // Valid insert.
-
-                Entity e1 = (Entity)ses.load(Entity.class, 1);
-
-                e1.setName("name-10"); // Valid update.
-
-                ses.delete(ses.load(Entity.class, 0)); // Invalid delete (there is a parent entity referencing it).
-
-                tx.commit();
-
-                fail("Commit must fail.");
-            }
-            catch (ConstraintViolationException e) {
-                log.info("Expected exception: " + e);
-
-                tx.rollback();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName, 3);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName, 3);
-
-            ses = sesFactory1.openSession();
-
-            tx = ses.beginTransaction();
-
-            try {
-                ses.delete(ses.load(Entity.class, 1)); // Valid delete.
-
-                idToName.remove(1);
-
-                ses.delete(ses.load(Entity.class, 0)); // Invalid delete (there is a parent entity referencing it).
-
-                tx.commit();
-
-                fail("Commit must fail.");
-            }
-            catch (ConstraintViolationException e) {
-                log.info("Expected exception: " + e);
-
-                tx.rollback();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEntityCache(ENTITY_NAME, sesFactory2, idToName);
-            assertEntityCache(ENTITY_NAME, sesFactory1, idToName);
-        }
-        finally {
-            cleanup();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testQueryCache() throws Exception {
-        for (AccessType accessType : accessTypes())
-            testQueryCache(accessType);
-    }
-
-    /**
-     * @param accessType Cache access type.
-     * @throws Exception If failed.
-     */
-    private void testQueryCache(AccessType accessType) throws Exception {
-        createSessionFactories(accessType);
-
-        try {
-            Session ses = sesFactory1.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                for (int i = 0; i < 5; i++)
-                    ses.save(new Entity(i, "name-" + i));
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            // Run some queries.
-
-            ses = sesFactory1.openSession();
-
-            try {
-                Query qry1 = ses.createQuery("from " + ENTITY_NAME + " where id > 2");
-
-                qry1.setCacheable(true);
-
-                assertEquals(2, qry1.list().size());
-
-                Query qry2 = ses.createQuery("from " + ENTITY_NAME + " where name = 'name-0'");
-
-                qry2.setCacheable(true);
-
-                assertEquals(1, qry2.list().size());
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEquals(0, sesFactory1.getStatistics().getQueryCacheHitCount());
-            assertEquals(2, sesFactory1.getStatistics().getQueryCacheMissCount());
-            assertEquals(2, sesFactory1.getStatistics().getQueryCachePutCount());
-
-            // Run queries using another SessionFactory.
-
-            ses = sesFactory2.openSession();
-
-            try {
-                Query qry1 = ses.createQuery("from " + ENTITY_NAME + " where id > 2");
-
-                qry1.setCacheable(true);
-
-                assertEquals(2, qry1.list().size());
-
-                Query qry2 = ses.createQuery("from " + ENTITY_NAME + " where name = 'name-0'");
-
-                qry2.setCacheable(true);
-
-                assertEquals(1, qry2.list().size());
-
-                Query qry3 = ses.createQuery("from " + ENTITY_NAME + " where id > 1");
-
-                qry3.setCacheable(true);
-
-                assertEquals(3, qry3.list().size());
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEquals(2, sesFactory2.getStatistics().getQueryCacheHitCount());
-            assertEquals(1, sesFactory2.getStatistics().getQueryCacheMissCount());
-            assertEquals(1, sesFactory2.getStatistics().getQueryCachePutCount());
-
-            // Update entity, it should invalidate query cache.
-
-            ses = sesFactory1.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                ses.save(new Entity(5, "name-5"));
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            // Run queries.
-
-            ses = sesFactory1.openSession();
-
-            sesFactory1.getStatistics().clear();
-
-            try {
-                Query qry1 = ses.createQuery("from " + ENTITY_NAME + " where id > 2");
-
-                qry1.setCacheable(true);
-
-                assertEquals(3, qry1.list().size());
-
-                Query qry2 = ses.createQuery("from " + ENTITY_NAME + " where name = 'name-0'");
-
-                qry2.setCacheable(true);
-
-                assertEquals(1, qry2.list().size());
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEquals(0, sesFactory1.getStatistics().getQueryCacheHitCount());
-            assertEquals(2, sesFactory1.getStatistics().getQueryCacheMissCount());
-            assertEquals(2, sesFactory1.getStatistics().getQueryCachePutCount());
-
-            // Clear query cache using another SessionFactory.
-
-            sesFactory2.getCache().evictDefaultQueryRegion();
-
-            ses = sesFactory1.openSession();
-
-            // Run queries again.
-
-            sesFactory1.getStatistics().clear();
-
-            try {
-                Query qry1 = ses.createQuery("from " + ENTITY_NAME + " where id > 2");
-
-                qry1.setCacheable(true);
-
-                assertEquals(3, qry1.list().size());
-
-                Query qry2 = ses.createQuery("from " + ENTITY_NAME + " where name = 'name-0'");
-
-                qry2.setCacheable(true);
-
-                assertEquals(1, qry2.list().size());
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEquals(0, sesFactory1.getStatistics().getQueryCacheHitCount());
-            assertEquals(2, sesFactory1.getStatistics().getQueryCacheMissCount());
-            assertEquals(2, sesFactory1.getStatistics().getQueryCachePutCount());
-        }
-        finally {
-            cleanup();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testRegionClear() throws Exception {
-        for (AccessType accessType : accessTypes())
-            testRegionClear(accessType);
-    }
-
-    /**
-     * @param accessType Cache access type.
-     * @throws Exception If failed.
-     */
-    private void testRegionClear(AccessType accessType) throws Exception {
-        createSessionFactories(accessType);
-
-        try {
-            final int ENTITY_CNT = 100;
-
-            Session ses = sesFactory1.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                for (int i = 0; i < ENTITY_CNT; i++) {
-                    Entity e = new Entity(i, "name-" + i);
-
-                    Collection<ChildEntity> children = new ArrayList<>();
-
-                    for (int j = 0; j < 3; j++)
-                        children.add(new ChildEntity());
-
-                    e.setChildren(children);
-
-                    ses.save(e);
-                }
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            loadEntities(sesFactory2, ENTITY_CNT);
-
-            SecondLevelCacheStatistics stats1 = sesFactory1.getStatistics().getSecondLevelCacheStatistics(ENTITY_NAME);
-            SecondLevelCacheStatistics stats2 = sesFactory2.getStatistics().getSecondLevelCacheStatistics(ENTITY_NAME);
-
-            NaturalIdCacheStatistics idStats1 =
-                sesFactory1.getStatistics().getNaturalIdCacheStatistics(NATURAL_ID_REGION);
-            NaturalIdCacheStatistics idStats2 =
-                sesFactory2.getStatistics().getNaturalIdCacheStatistics(NATURAL_ID_REGION);
-
-            SecondLevelCacheStatistics colStats1 =
-                sesFactory1.getStatistics().getSecondLevelCacheStatistics(CHILD_COLLECTION_REGION);
-            SecondLevelCacheStatistics colStats2 =
-                sesFactory2.getStatistics().getSecondLevelCacheStatistics(CHILD_COLLECTION_REGION);
-
-            assertEquals(ENTITY_CNT, stats1.getElementCountInMemory());
-            assertEquals(ENTITY_CNT, stats2.getElementCountInMemory());
-
-            assertEquals(ENTITY_CNT, idStats1.getElementCountInMemory());
-            assertEquals(ENTITY_CNT, idStats2.getElementCountInMemory());
-
-            assertEquals(ENTITY_CNT, colStats1.getElementCountInMemory());
-            assertEquals(ENTITY_CNT, colStats2.getElementCountInMemory());
-
-            // Test cache is cleared after update query.
-
-            ses = sesFactory1.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                ses.createQuery("delete from " + ENTITY_NAME + " where name='no such name'").executeUpdate();
-
-                ses.createQuery("delete from " + ChildEntity.class.getName() + " where id=-1").executeUpdate();
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            assertEquals(0, stats1.getElementCountInMemory());
-            assertEquals(0, stats2.getElementCountInMemory());
-
-            assertEquals(0, idStats1.getElementCountInMemory());
-            assertEquals(0, idStats2.getElementCountInMemory());
-
-            assertEquals(0, colStats1.getElementCountInMemory());
-            assertEquals(0, colStats2.getElementCountInMemory());
-
-            // Load some data in cache.
-
-            loadEntities(sesFactory1, 10);
-
-            assertEquals(10, stats1.getElementCountInMemory());
-            assertEquals(10, stats2.getElementCountInMemory());
-            assertEquals(10, idStats1.getElementCountInMemory());
-            assertEquals(10, idStats2.getElementCountInMemory());
-
-            // Test evictAll method.
-
-            sesFactory2.getCache().evictEntityRegion(ENTITY_NAME);
-
-            assertEquals(0, stats1.getElementCountInMemory());
-            assertEquals(0, stats2.getElementCountInMemory());
-
-            sesFactory2.getCache().evictNaturalIdRegion(ENTITY_NAME);
-
-            assertEquals(0, idStats1.getElementCountInMemory());
-            assertEquals(0, idStats2.getElementCountInMemory());
-
-            sesFactory2.getCache().evictCollectionRegion(CHILD_COLLECTION_REGION);
-
-            assertEquals(0, colStats1.getElementCountInMemory());
-            assertEquals(0, colStats2.getElementCountInMemory());
-        }
-        finally {
-            cleanup();
-        }
-    }
-
-    /**
-     * @param sesFactory Session factory.
-     * @param nameToId Name-ID mapping.
-     * @param absentNames Absent entities' names.
-     */
-    private void assertNaturalIdCache(SessionFactory sesFactory, Map<String, Integer> nameToId, String... absentNames) {
-        sesFactory.getStatistics().clear();
-
-        NaturalIdCacheStatistics stats =
-            sesFactory.getStatistics().getNaturalIdCacheStatistics(NATURAL_ID_REGION);
-
-        long hitBefore = stats.getHitCount();
-
-        long missBefore = stats.getMissCount();
-
-        final Session ses = sesFactory.openSession();
-
-        try {
-            for (Map.Entry<String, Integer> e : nameToId.entrySet())
-                assertEquals((int)e.getValue(), ((Entity)ses.bySimpleNaturalId(Entity.class).load(e.getKey())).getId());
-
-            for (String name : absentNames)
-                assertNull((ses.bySimpleNaturalId(Entity.class).load(name)));
-
-            assertEquals(nameToId.size() + hitBefore, stats.getHitCount());
-
-            assertEquals(absentNames.length + missBefore, stats.getMissCount());
-        }
-        finally {
-            ses.close();
-        }
-    }
-
-    /**
-     * @param sesFactory Session factory.
-     * @param idToChildCnt Number of children per entity.
-     * @param expHit Expected cache hits.
-     * @param expMiss Expected cache misses.
-     */
-    @SuppressWarnings("unchecked")
-    private void assertCollectionCache(SessionFactory sesFactory, Map<Integer, Integer> idToChildCnt, int expHit,
-        int expMiss) {
-        sesFactory.getStatistics().clear();
-
-        Session ses = sesFactory.openSession();
-
-        try {
-            for(Map.Entry<Integer, Integer> e : idToChildCnt.entrySet()) {
-                Entity entity = (Entity)ses.load(Entity.class, e.getKey());
-
-                assertEquals((int)e.getValue(), entity.getChildren().size());
-            }
-        }
-        finally {
-            ses.close();
-        }
-
-        SecondLevelCacheStatistics stats =
-            sesFactory.getStatistics().getSecondLevelCacheStatistics(CHILD_COLLECTION_REGION);
-
-        assertEquals(expHit, stats.getHitCount());
-
-        assertEquals(expMiss, stats.getMissCount());
-    }
-
-    /**
-     * @param sesFactory Session factory.
-     * @param cnt Number of entities to load.
-     */
-    private void loadEntities(SessionFactory sesFactory, int cnt) {
-        Session ses = sesFactory.openSession();
-
-        try {
-            for (int i = 0; i < cnt; i++) {
-                Entity e = (Entity)ses.load(Entity.class, i);
-
-                assertEquals("name-" + i, e.getName());
-
-                assertFalse(e.getChildren().isEmpty());
-
-                ses.bySimpleNaturalId(Entity.class).load(e.getName());
-            }
-        }
-        finally {
-            ses.close();
-        }
-    }
-
-    /**
-     * @param entityName Entity name.
-     * @param sesFactory Session factory.
-     * @param idToName ID to name mapping.
-     * @param absentIds Absent entities' IDs.
-     */
-    private void assertEntityCache(String entityName, SessionFactory sesFactory, Map<Integer, String> idToName,
-        Integer... absentIds) {
-        assert entityName.equals(ENTITY_NAME) || entityName.equals(ENTITY2_NAME) : entityName;
-
-        sesFactory.getStatistics().clear();
-
-        final Session ses = sesFactory.openSession();
-
-        final boolean entity1 = entityName.equals(ENTITY_NAME);
-
-        try {
-            if (entity1) {
-                for (Map.Entry<Integer, String> e : idToName.entrySet())
-                    assertEquals(e.getValue(), ((Entity)ses.load(Entity.class, e.getKey())).getName());
-            }
-            else {
-                for (Map.Entry<Integer, String> e : idToName.entrySet())
-                    assertEquals(e.getValue(), ((Entity2)ses.load(Entity2.class, e.getKey())).getName());
-            }
-
-            for (final int id : absentIds) {
-                GridTestUtils.assertThrows(log, new Callable<Void>() {
-                    @Override public Void call() throws Exception {
-                        if (entity1)
-                            ((Entity)ses.load(Entity.class, id)).getName();
-                        else
-                            ((Entity2)ses.load(Entity2.class, id)).getName();
-
-                        return null;
-                    }
-                }, ObjectNotFoundException.class, null);
-            }
-
-            SecondLevelCacheStatistics stats = sesFactory.getStatistics().getSecondLevelCacheStatistics(entityName);
-
-            assertEquals(idToName.size(), stats.getHitCount());
-
-            assertEquals(absentIds.length, stats.getMissCount());
-        }
-        finally {
-            ses.close();
-        }
-    }
-
-    /**
-     * Creates session factories.
-     *
-     * @param accessType Cache access type.
-     */
-    private void createSessionFactories(AccessType accessType) {
-        sesFactory1 = startHibernate(accessType, getTestIgniteInstanceName(0));
-
-        sesFactory2 = startHibernate(accessType, getTestIgniteInstanceName(1));
-    }
-
-    /**
-     * Starts Hibernate.
-     *
-     * @param accessType Cache access type.
-     * @param igniteInstanceName Ignite instance name.
-     * @return Session factory.
-     */
-    private SessionFactory startHibernate(AccessType accessType, String igniteInstanceName) {
-        Configuration cfg = hibernateConfiguration(accessType, igniteInstanceName);
-
-        ServiceRegistryBuilder builder = registryBuilder();
-
-        builder.applySetting("hibernate.show_sql", false);
-
-        return cfg.buildSessionFactory(builder.buildServiceRegistry());
-    }
-
-    /**
-     * Closes session factories and clears data from caches.
-     *
-     * @throws Exception If failed.
-     */
-    private void cleanup() throws Exception {
-        if (sesFactory1 != null)
-            sesFactory1.close();
-
-        sesFactory1 = null;
-
-        if (sesFactory2 != null)
-            sesFactory2.close();
-
-        sesFactory2 = null;
-
-        for (IgniteCacheProxy<?, ?> cache : ((IgniteKernal)grid(0)).caches())
-            cache.clear();
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalSelfTest.java b/modules/hibernate/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalSelfTest.java
deleted file mode 100644
index deca893..0000000
--- a/modules/hibernate/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalSelfTest.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import java.util.Collections;
-import javax.cache.configuration.Factory;
-import javax.transaction.Synchronization;
-import javax.transaction.TransactionManager;
-import javax.transaction.UserTransaction;
-import org.apache.commons.dbcp.managed.BasicManagedDataSource;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.h2.jdbcx.JdbcDataSource;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.engine.transaction.internal.jta.JtaTransactionFactory;
-import org.hibernate.engine.transaction.spi.TransactionFactory;
-import org.hibernate.service.ServiceRegistryBuilder;
-import org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl;
-import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
-import org.hibernate.service.jta.platform.internal.AbstractJtaPlatform;
-import org.hibernate.service.jta.platform.spi.JtaPlatform;
-import org.jetbrains.annotations.Nullable;
-import org.objectweb.jotm.Jotm;
-
-/**
- *
- * Tests Hibernate L2 cache with TRANSACTIONAL access mode (Hibernate and Cache are configured
- * to used the same TransactionManager).
- */
-public class HibernateL2CacheTransactionalSelfTest extends HibernateL2CacheSelfTest {
-    /** */
-    private static Jotm jotm;
-
-    /**
-     */
-    private static class TestJtaPlatform extends AbstractJtaPlatform {
-        /** {@inheritDoc} */
-        @Override protected TransactionManager locateTransactionManager() {
-            return jotm.getTransactionManager();
-        }
-
-        /** {@inheritDoc} */
-        @Override protected UserTransaction locateUserTransaction() {
-            return jotm.getUserTransaction();
-        }
-    }
-
-    /**
-     */
-    @SuppressWarnings("PublicInnerClass")
-    public static class TestTmFactory implements Factory<TransactionManager> {
-        /** */
-        private static final long serialVersionUID = 0;
-
-        /** {@inheritDoc} */
-        @Override public TransactionManager create() {
-            return jotm.getTransactionManager();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        jotm = new Jotm(true, false);
-
-        super.beforeTestsStarted();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        super.afterTestsStopped();
-
-        if (jotm != null)
-            jotm.stop();
-
-        jotm = null;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
-
-        cfg.getTransactionConfiguration().setTxManagerFactory(new TestTmFactory());
-        cfg.getTransactionConfiguration().setUseJtaSynchronization(useJtaSynchronization());
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheConfiguration transactionalRegionConfiguration(String regionName) {
-        CacheConfiguration cfg = super.transactionalRegionConfiguration(regionName);
-
-        cfg.setNearConfiguration(null);
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override protected ServiceRegistryBuilder registryBuilder() {
-        ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
-
-        DatasourceConnectionProviderImpl connProvider = new DatasourceConnectionProviderImpl();
-
-        BasicManagedDataSource dataSrc = new BasicManagedDataSource(); // JTA-aware data source.
-
-        dataSrc.setTransactionManager(jotm.getTransactionManager());
-
-        dataSrc.setDefaultAutoCommit(false);
-
-        JdbcDataSource h2DataSrc = new JdbcDataSource();
-
-        h2DataSrc.setURL(CONNECTION_URL);
-
-        dataSrc.setXaDataSourceInstance(h2DataSrc);
-
-        connProvider.setDataSource(dataSrc);
-
-        connProvider.configure(Collections.emptyMap());
-
-        builder.addService(ConnectionProvider.class, connProvider);
-
-        builder.addService(JtaPlatform.class, new TestJtaPlatform());
-
-        builder.addService(TransactionFactory.class, new JtaTransactionFactory());
-
-        return builder;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected AccessType[] accessTypes() {
-        return new AccessType[]{AccessType.TRANSACTIONAL};
-    }
-
-    /**
-     * @return Whether to use {@link Synchronization}.
-     */
-    protected boolean useJtaSynchronization() {
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalUseSyncSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalUseSyncSelfTest.java b/modules/hibernate/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalUseSyncSelfTest.java
deleted file mode 100644
index 44899f9..0000000
--- a/modules/hibernate/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalUseSyncSelfTest.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import javax.transaction.Synchronization;
-
-/**
- * Tests Hibernate L2 cache with TRANSACTIONAL access mode and {@link Synchronization}
- * instead of XA resource.
- */
-public class HibernateL2CacheTransactionalUseSyncSelfTest extends HibernateL2CacheTransactionalSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean useJtaSynchronization() {
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreNodeRestartTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreNodeRestartTest.java b/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreNodeRestartTest.java
deleted file mode 100644
index d5496af..0000000
--- a/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreNodeRestartTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.store.hibernate;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.cache.store.CacheStore;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.integration.IgniteCacheStoreNodeRestartAbstractTest;
-
-public class CacheHibernateBlobStoreNodeRestartTest extends IgniteCacheStoreNodeRestartAbstractTest {
-    /** {@inheritDoc} */
-    @Override protected CacheStore getStore() {
-        return new CacheHibernateBlobStore();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheMode cacheMode() {
-        return CacheMode.PARTITIONED;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheAtomicityMode atomicityMode() {
-        return CacheAtomicityMode.ATOMIC;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected NearCacheConfiguration nearConfiguration() {
-        return null;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreSelfTest.java b/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreSelfTest.java
deleted file mode 100644
index d3d2b52..0000000
--- a/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreSelfTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.store.hibernate;
-
-import java.io.File;
-import java.net.URL;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.testframework.junits.cache.GridAbstractCacheStoreSelfTest;
-import org.hibernate.FlushMode;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-
-/**
- * Cache store test.
- */
-public class CacheHibernateBlobStoreSelfTest extends
-    GridAbstractCacheStoreSelfTest<CacheHibernateBlobStore<Object, Object>> {
-    /**
-     * @throws Exception If failed.
-     */
-    public CacheHibernateBlobStoreSelfTest() throws Exception {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        super.afterTest();
-
-        Session s = store.session(null);
-
-        if (s == null)
-            return;
-
-        try {
-            s.createQuery("delete from " + CacheHibernateBlobStoreEntry.class.getSimpleName())
-                    .setFlushMode(FlushMode.ALWAYS).executeUpdate();
-
-            Transaction hTx = s.getTransaction();
-
-            if (hTx != null && hTx.isActive())
-                hTx.commit();
-        }
-        finally {
-            s.close();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheHibernateBlobStore<Object, Object> store() {
-        return new CacheHibernateBlobStore<>();
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testConfigurationByUrl() throws Exception {
-        URL url = U.resolveIgniteUrl(
-                "modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml");
-
-        assert url != null;
-
-        store.setHibernateConfigurationPath(url.toString());
-
-        // Store will be implicitly initialized.
-        store.load("key");
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testConfigurationByFile() throws Exception {
-        URL url = U.resolveIgniteUrl(
-                "modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml");
-
-        assert url != null;
-
-        File file = new File(url.toURI());
-
-        store.setHibernateConfigurationPath(file.getAbsolutePath());
-
-        // Store will be implicitly initialized.
-        store.load("key");
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testConfigurationByResource() throws Exception {
-        store.setHibernateConfigurationPath("/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml");
-
-        // Store will be implicitly initialized.
-        store.load("key");
-    }
-
-    @Override public void testSimpleMultithreading() throws Exception {
-        fail("https://issues.apache.org/jira/browse/IGNITE-1757");
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreFactorySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreFactorySelfTest.java b/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreFactorySelfTest.java
deleted file mode 100644
index 3a2244e..0000000
--- a/modules/hibernate/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreFactorySelfTest.java
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.store.hibernate;
-
-import java.io.Serializable;
-import java.sql.Connection;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import javax.naming.NamingException;
-import javax.naming.Reference;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.hibernate.Cache;
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.SessionBuilder;
-import org.hibernate.SessionFactory;
-import org.hibernate.StatelessSession;
-import org.hibernate.StatelessSessionBuilder;
-import org.hibernate.TypeHelper;
-import org.hibernate.engine.spi.FilterDefinition;
-import org.hibernate.metadata.ClassMetadata;
-import org.hibernate.metadata.CollectionMetadata;
-import org.hibernate.stat.Statistics;
-
-/**
- * Test for Cache jdbc blob store factory.
- */
-public class CacheHibernateStoreFactorySelfTest extends GridCommonAbstractTest {
-    /** Cache name. */
-    private static final String CACHE_NAME = "test";
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testCacheConfiguration() throws Exception {
-        try (Ignite ignite1 = startGrid(0)) {
-            IgniteCache<Integer, String> cache1 = ignite1.getOrCreateCache(cacheConfiguration());
-
-            checkStore(cache1);
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testXmlConfiguration() throws Exception {
-        try (Ignite ignite = Ignition.start("modules/hibernate/src/test/config/factory-cache.xml")) {
-            try(Ignite ignite1 = Ignition.start("modules/hibernate/src/test/config/factory-cache1.xml")) {
-                checkStore(ignite.<Integer, String>cache(CACHE_NAME), DummySessionFactoryExt.class);
-
-                checkStore(ignite1.<Integer, String>cache(CACHE_NAME), DummySessionFactory.class);
-            }
-        }
-    }
-
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testIncorrectBeanConfiguration() throws Exception {
-        GridTestUtils.assertThrows(log, new Callable<Object>() {
-            @Override public Object call() throws Exception {
-                try(Ignite ignite =
-                    Ignition.start("modules/hibernate/src/test/config/factory-incorrect-store-cache.xml")) {
-                    ignite.cache(CACHE_NAME).getConfiguration(CacheConfiguration.class).
-                            getCacheStoreFactory().create();
-                }
-                return null;
-            }
-        }, IgniteException.class, "Failed to load bean in application context");
-    }
-
-    /**
-     * @return Cache configuration with store.
-     */
-    private CacheConfiguration<Integer, String> cacheConfiguration() {
-        CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>();
-
-        CacheHibernateBlobStoreFactory<Integer, String> factory = new CacheHibernateBlobStoreFactory();
-
-        factory.setHibernateConfigurationPath("/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml");
-
-        cfg.setCacheStoreFactory(factory);
-
-        return cfg;
-    }
-
-    /**
-     * @param cache Ignite cache.
-     * @param dataSrcClass Data source class.
-     * @throws Exception If store parameters is not the same as in configuration xml.
-     */
-    private void checkStore(IgniteCache<Integer, String> cache, Class<?> dataSrcClass) throws Exception {
-        CacheHibernateBlobStore store = (CacheHibernateBlobStore)cache
-            .getConfiguration(CacheConfiguration.class).getCacheStoreFactory().create();
-
-        assertEquals(dataSrcClass,
-            GridTestUtils.getFieldValue(store, CacheHibernateBlobStore.class, "sesFactory").getClass());
-    }
-
-    /**
-     * @param cache Ignite cache.
-     * @throws Exception If store parameters is not the same as in configuration xml.
-     */
-    private void checkStore(IgniteCache<Integer, String> cache) throws Exception {
-        CacheHibernateBlobStore store = (CacheHibernateBlobStore)cache.getConfiguration(CacheConfiguration.class)
-            .getCacheStoreFactory().create();
-
-        assertEquals("/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml",
-            GridTestUtils.getFieldValue(store, CacheHibernateBlobStore.class, "hibernateCfgPath"));
-    }
-
-    /**
-     *
-     */
-    public static class DummySessionFactoryExt extends DummySessionFactory {
-        /** */
-        public DummySessionFactoryExt() {
-            // No-op.
-        }
-    }
-
-    /**
-     *
-     */
-    public static class DummySessionFactory implements SessionFactory {
-        /** {@inheritDoc} */
-        @Override public SessionFactoryOptions getSessionFactoryOptions() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public SessionBuilder withOptions() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Session openSession() throws HibernateException {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Session getCurrentSession() throws HibernateException {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public StatelessSessionBuilder withStatelessOptions() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public StatelessSession openStatelessSession() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public StatelessSession openStatelessSession(Connection connection) {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public ClassMetadata getClassMetadata(Class entityClass) {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public ClassMetadata getClassMetadata(String entityName) {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public CollectionMetadata getCollectionMetadata(String roleName) {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Map<String, ClassMetadata> getAllClassMetadata() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Map getAllCollectionMetadata() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Statistics getStatistics() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void close() throws HibernateException {
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean isClosed() {
-            return false;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Cache getCache() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void evict(Class persistentClass) throws HibernateException {
-        }
-
-        /** {@inheritDoc} */
-        @Override public void evict(Class persistentClass, Serializable id) throws HibernateException {
-        }
-
-        /** {@inheritDoc} */
-        @Override public void evictEntity(String entityName) throws HibernateException {
-        }
-
-        /** {@inheritDoc} */
-        @Override public void evictEntity(String entityName, Serializable id) throws HibernateException {
-        }
-
-        /** {@inheritDoc} */
-        @Override public void evictCollection(String roleName) throws HibernateException {
-        }
-
-        /** {@inheritDoc} */
-        @Override public void evictCollection(String roleName, Serializable id) throws HibernateException {
-        }
-
-        /** {@inheritDoc} */
-        @Override public void evictQueries(String cacheRegion) throws HibernateException {
-        }
-
-        /** {@inheritDoc} */
-        @Override public void evictQueries() throws HibernateException {
-        }
-
-        /** {@inheritDoc} */
-        @Override public Set getDefinedFilterNames() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public FilterDefinition getFilterDefinition(String filterName) throws HibernateException {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean containsFetchProfileDefinition(String name) {
-            return false;
-        }
-
-        /** {@inheritDoc} */
-        @Override public TypeHelper getTypeHelper() {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Reference getReference() throws NamingException {
-            return null;
-        }
-    }
-}
\ No newline at end of file


[09/16] ignite git commit: ignite-1794 Refactored hibernate modules, switched to hibernate 5.1

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadWriteAccessStrategy.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadWriteAccessStrategy.java b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadWriteAccessStrategy.java
new file mode 100644
index 0000000..491553d
--- /dev/null
+++ b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadWriteAccessStrategy.java
@@ -0,0 +1,326 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import java.util.Set;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
+import org.apache.ignite.internal.util.GridLeanSet;
+
+import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
+
+/**
+ * Implementation of READ_WRITE cache access strategy.
+ * <p>
+ * Configuration of L2 cache and per-entity cache access strategy can be set in the
+ * Hibernate configuration file:
+ * <pre name="code" class="xml">
+ * &lt;hibernate-configuration&gt;
+ *     &lt;!-- Enable L2 cache. --&gt;
+ *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
+ *
+ *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
+ *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
+ *
+ *     &lt;!-- Specify entity. --&gt;
+ *     &lt;mapping class="com.example.Entity"/&gt;
+ *
+ *     &lt;!-- Enable L2 cache with read-write access strategy for entity. --&gt;
+ *     &lt;class-cache class="com.example.Entity" usage="read-write"/&gt;
+ * &lt;/hibernate-configuration&gt;
+ * </pre>
+ * Also cache access strategy can be set using annotations:
+ * <pre name="code" class="java">
+ * &#064;javax.persistence.Entity
+ * &#064;javax.persistence.Cacheable
+ * &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
+ * public class Entity { ... }
+ * </pre>
+ */
+public class HibernateReadWriteAccessStrategy extends HibernateAccessStrategyAdapter {
+    /** */
+    private final ThreadLocal<TxContext> txCtx;
+
+    /**
+     * @param ignite Grid.
+     * @param cache Cache.
+     * @param txCtx Thread local instance used to track updates done during one Hibernate transaction.
+     * @param eConverter Exception converter.
+     */
+    protected HibernateReadWriteAccessStrategy(Ignite ignite,
+        HibernateCacheProxy cache,
+        ThreadLocal txCtx,
+        HibernateExceptionConverter eConverter) {
+        super(ignite, cache, eConverter);
+
+        this.txCtx = (ThreadLocal<TxContext>)txCtx;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object get(Object key) {
+        boolean success = false;
+
+        try {
+            Object o = cache.get(key);
+
+            success = true;
+
+            return o;
+        }
+        catch (IgniteCheckedException e) {
+            throw convertException(e);
+        }
+        finally {
+            if (!success)
+                rollbackCurrentTx();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void putFromLoad(Object key, Object val) {
+        boolean success = false;
+
+        try {
+            cache.put(key, val);
+
+            success = true;
+        }
+        catch (IgniteCheckedException e) {
+            throw convertException(e);
+        }
+        finally {
+            if (!success)
+                rollbackCurrentTx();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void lock(Object key) {
+        boolean success = false;
+
+        try {
+            TxContext ctx = txCtx.get();
+
+            if (ctx == null)
+                txCtx.set(ctx = new TxContext());
+
+            lockKey(key);
+
+            ctx.locked(key);
+
+            success = true;
+        }
+        catch (IgniteCheckedException e) {
+            throw convertException(e);
+        }
+        finally {
+            if (!success)
+                rollbackCurrentTx();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unlock(Object key) {
+        boolean success = false;
+
+        try {
+            TxContext ctx = txCtx.get();
+
+            if (ctx != null)
+                unlock(ctx, key);
+
+            success = true;
+        }
+        catch (Exception e) {
+            throw convertException(e);
+        }
+        finally {
+            if (!success)
+                rollbackCurrentTx();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean update(Object key, Object val) {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean afterUpdate(Object key, Object val) {
+        boolean success = false;
+        boolean res = false;
+
+        try {
+            TxContext ctx = txCtx.get();
+
+            if (ctx != null) {
+                cache.put(key, val);
+
+                unlock(ctx, key);
+
+                res = true;
+            }
+
+            success = true;
+
+            return res;
+        }
+        catch (Exception e) {
+            throw convertException(e);
+        }
+        finally {
+            if (!success)
+                rollbackCurrentTx();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean insert(Object key, Object val) {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean afterInsert(Object key, Object val) {
+        boolean success = false;
+
+        try {
+            cache.put(key, val);
+
+            success = true;
+
+            return true;
+        }
+        catch (IgniteCheckedException e) {
+            throw convertException(e);
+        }
+        finally {
+            if (!success)
+                rollbackCurrentTx();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void remove(Object key) {
+        boolean success = false;
+
+        try {
+            TxContext ctx = txCtx.get();
+
+            if (ctx != null)
+                cache.remove(key);
+
+            success = true;
+        }
+        catch (IgniteCheckedException e) {
+            throw convertException(e);
+        }
+        finally {
+            if (!success)
+                rollbackCurrentTx();
+        }
+    }
+
+    /**
+     *
+     * @param ctx Transaction context.
+     * @param key Key.
+     */
+    private void unlock(TxContext ctx, Object key) {
+        if (ctx.unlocked(key)) { // Finish transaction if last key is unlocked.
+            txCtx.remove();
+
+            GridNearTxLocal tx = cache.tx();
+
+            assert tx != null;
+
+            try {
+                tx.proxy().commit();
+            }
+            finally {
+                tx.proxy().close();
+            }
+
+            assert cache.tx() == null;
+        }
+    }
+
+    /**
+     * Roll backs current transaction.
+     */
+    private void rollbackCurrentTx() {
+        try {
+            TxContext ctx = txCtx.get();
+
+            if (ctx != null) {
+                txCtx.remove();
+
+                GridNearTxLocal tx = cache.tx();
+
+                if (tx != null)
+                    tx.proxy().rollback();
+            }
+        }
+        catch (IgniteException e) {
+            log.error("Failed to rollback cache transaction.", e);
+        }
+    }
+
+    /**
+     * @param key Key.
+     * @throws IgniteCheckedException If failed.
+     */
+    private void lockKey(Object key) throws IgniteCheckedException {
+        if (cache.tx() == null)
+            cache.txStart(PESSIMISTIC, REPEATABLE_READ);
+
+        cache.get(key); // Acquire distributed lock.
+    }
+
+    /**
+     * Information about updates done during single database transaction.
+     */
+    @SuppressWarnings("TypeMayBeWeakened")
+    private static class TxContext {
+        /** */
+        private Set<Object> locked = new GridLeanSet<>();
+
+        /**
+         * Marks key as locked.
+         *
+         * @param key Key.
+         */
+        void locked(Object key) {
+            locked.add(key);
+        }
+
+        /**
+         * Marks key as unlocked.
+         *
+         * @param key Key.
+         * @return {@code True} if last locked key was unlocked.
+         */
+        boolean unlocked(Object key) {
+            locked.remove(key);
+
+            return locked.isEmpty();
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalAccessStrategy.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalAccessStrategy.java b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalAccessStrategy.java
new file mode 100644
index 0000000..6f4935b
--- /dev/null
+++ b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalAccessStrategy.java
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Implementation of {TRANSACTIONAL cache access strategy.
+ * <p>
+ * It is supposed that this strategy is used in JTA environment and Hibernate and
+ * {@link IgniteInternalCache} corresponding to the L2 cache region are configured to use the same transaction manager.
+ * <p>
+ * Configuration of L2 cache and per-entity cache access strategy can be set in the
+ * Hibernate configuration file:
+ * <pre name="code" class="xml">
+ * &lt;hibernate-configuration&gt;
+ *     &lt;!-- Enable L2 cache. --&gt;
+ *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
+ *
+ *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
+ *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
+ *
+ *     &lt;!-- Specify entity. --&gt;
+ *     &lt;mapping class="com.example.Entity"/&gt;
+ *
+ *     &lt;!-- Enable L2 cache with transactional access strategy for entity. --&gt;
+ *     &lt;class-cache class="com.example.Entity" usage="transactional"/&gt;
+ * &lt;/hibernate-configuration&gt;
+ * </pre>
+ * Also cache access strategy can be set using annotations:
+ * <pre name="code" class="java">
+ * &#064;javax.persistence.Entity
+ * &#064;javax.persistence.Cacheable
+ * &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
+ * public class Entity { ... }
+ * </pre>
+ */
+public class HibernateTransactionalAccessStrategy extends HibernateAccessStrategyAdapter {
+    /**
+     * @param ignite Grid.
+     * @param cache Cache.
+     * @param eConverter Exception converter.
+     */
+    HibernateTransactionalAccessStrategy(Ignite ignite,
+        HibernateCacheProxy cache,
+        HibernateExceptionConverter eConverter) {
+        super(ignite, cache, eConverter);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public Object get(Object key) {
+        try {
+            return cache.get(key);
+        }
+        catch (IgniteCheckedException e) {
+            throw convertException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void putFromLoad(Object key, Object val) {
+        try {
+            cache.put(key, val);
+        }
+        catch (IgniteCheckedException e) {
+            throw convertException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void lock(Object key) {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unlock(Object key) {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean update(Object key, Object val) {
+        try {
+            cache.put(key, val);
+
+            return true;
+        }
+        catch (IgniteCheckedException e) {
+            throw convertException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean afterUpdate(Object key, Object val) {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean insert(Object key, Object val) {
+        try {
+            cache.put(key, val);
+
+            return true;
+        }
+        catch (IgniteCheckedException e) {
+            throw convertException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean afterInsert(Object key, Object val) {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void remove(Object key) {
+        try {
+            cache.remove(key);
+        }
+        catch (IgniteCheckedException e) {
+            throw convertException(e);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/package-info.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/package-info.java b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/package-info.java
new file mode 100644
index 0000000..1179aec
--- /dev/null
+++ b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * <!-- Package description. -->
+ * Contains implementation of Hibernate L2 cache. Refer to
+ * <i>org.apache.ignite.examples.datagrid.hibernate.HibernateL2CacheExample</i> for more information on how to
+ * configure and use Ignite with Hibernate.
+ */
+package org.apache.ignite.cache.hibernate;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/README.txt
----------------------------------------------------------------------
diff --git a/modules/hibernate/README.txt b/modules/hibernate/README.txt
deleted file mode 100644
index 8e90dab..0000000
--- a/modules/hibernate/README.txt
+++ /dev/null
@@ -1,48 +0,0 @@
-Apache Ignite Hibernate Module
-------------------------------
-
-Apache Ignite Hibernate module provides Hibernate second-level cache (L2 cache) implementation based
-on Apache Ignite In-Memory Data Grid.
-
-To enable Hibernate module when starting a standalone node, move 'optional/ignite-hibernate' folder to
-'libs' folder before running 'ignite.{sh|bat}' script. The content of the module folder will
-be added to classpath in this case.
-
-Importing Hibernate Module In Maven Project
--------------------------------------------
-
-If you are using Maven to manage dependencies of your project, you can add Hibernate module
-dependency like this (replace '${ignite.version}' with actual Ignite version you are
-interested in):
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
-                        http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    ...
-    <dependencies>
-        ...
-        <dependency>
-            <groupId>org.apache.ignite</groupId>
-            <artifactId>ignite-hibernate</artifactId>
-            <version>${ignite.version}</version>
-        </dependency>
-        ...
-    </dependencies>
-    ...
-</project>
-
-
-LGPL dependencies
------------------
-
-Ignite includes the following optional LGPL dependencies:
- - Hibernate L2 Cache Integration, http://hibernate.org/orm/
- - JTS Topology Suite for Geospatial indexing, http://tsusiatsoftware.net/jts/main.html
- - cron4j for cron-based task scheduling, http://www.sauronsoftware.it/projects/cron4j
-
-Apache binary releases cannot include LGPL dependencies. If you would like include
-optional LGPL dependencies into your release, you should download the source release
-from Ignite website and do the build with the following maven command:
-
-mvn clean package -DskipTests -Prelease,lgpl

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/licenses/apache-2.0.txt
----------------------------------------------------------------------
diff --git a/modules/hibernate/licenses/apache-2.0.txt b/modules/hibernate/licenses/apache-2.0.txt
deleted file mode 100644
index d645695..0000000
--- a/modules/hibernate/licenses/apache-2.0.txt
+++ /dev/null
@@ -1,202 +0,0 @@
-
-                                 Apache License
-                           Version 2.0, January 2004
-                        http://www.apache.org/licenses/
-
-   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
-   1. Definitions.
-
-      "License" shall mean the terms and conditions for use, reproduction,
-      and distribution as defined by Sections 1 through 9 of this document.
-
-      "Licensor" shall mean the copyright owner or entity authorized by
-      the copyright owner that is granting the License.
-
-      "Legal Entity" shall mean the union of the acting entity and all
-      other entities that control, are controlled by, or are under common
-      control with that entity. For the purposes of this definition,
-      "control" means (i) the power, direct or indirect, to cause the
-      direction or management of such entity, whether by contract or
-      otherwise, or (ii) ownership of fifty percent (50%) or more of the
-      outstanding shares, or (iii) beneficial ownership of such entity.
-
-      "You" (or "Your") shall mean an individual or Legal Entity
-      exercising permissions granted by this License.
-
-      "Source" form shall mean the preferred form for making modifications,
-      including but not limited to software source code, documentation
-      source, and configuration files.
-
-      "Object" form shall mean any form resulting from mechanical
-      transformation or translation of a Source form, including but
-      not limited to compiled object code, generated documentation,
-      and conversions to other media types.
-
-      "Work" shall mean the work of authorship, whether in Source or
-      Object form, made available under the License, as indicated by a
-      copyright notice that is included in or attached to the work
-      (an example is provided in the Appendix below).
-
-      "Derivative Works" shall mean any work, whether in Source or Object
-      form, that is based on (or derived from) the Work and for which the
-      editorial revisions, annotations, elaborations, or other modifications
-      represent, as a whole, an original work of authorship. For the purposes
-      of this License, Derivative Works shall not include works that remain
-      separable from, or merely link (or bind by name) to the interfaces of,
-      the Work and Derivative Works thereof.
-
-      "Contribution" shall mean any work of authorship, including
-      the original version of the Work and any modifications or additions
-      to that Work or Derivative Works thereof, that is intentionally
-      submitted to Licensor for inclusion in the Work by the copyright owner
-      or by an individual or Legal Entity authorized to submit on behalf of
-      the copyright owner. For the purposes of this definition, "submitted"
-      means any form of electronic, verbal, or written communication sent
-      to the Licensor or its representatives, including but not limited to
-      communication on electronic mailing lists, source code control systems,
-      and issue tracking systems that are managed by, or on behalf of, the
-      Licensor for the purpose of discussing and improving the Work, but
-      excluding communication that is conspicuously marked or otherwise
-      designated in writing by the copyright owner as "Not a Contribution."
-
-      "Contributor" shall mean Licensor and any individual or Legal Entity
-      on behalf of whom a Contribution has been received by Licensor and
-      subsequently incorporated within the Work.
-
-   2. Grant of Copyright License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      copyright license to reproduce, prepare Derivative Works of,
-      publicly display, publicly perform, sublicense, and distribute the
-      Work and such Derivative Works in Source or Object form.
-
-   3. Grant of Patent License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      (except as stated in this section) patent license to make, have made,
-      use, offer to sell, sell, import, and otherwise transfer the Work,
-      where such license applies only to those patent claims licensable
-      by such Contributor that are necessarily infringed by their
-      Contribution(s) alone or by combination of their Contribution(s)
-      with the Work to which such Contribution(s) was submitted. If You
-      institute patent litigation against any entity (including a
-      cross-claim or counterclaim in a lawsuit) alleging that the Work
-      or a Contribution incorporated within the Work constitutes direct
-      or contributory patent infringement, then any patent licenses
-      granted to You under this License for that Work shall terminate
-      as of the date such litigation is filed.
-
-   4. Redistribution. You may reproduce and distribute copies of the
-      Work or Derivative Works thereof in any medium, with or without
-      modifications, and in Source or Object form, provided that You
-      meet the following conditions:
-
-      (a) You must give any other recipients of the Work or
-          Derivative Works a copy of this License; and
-
-      (b) You must cause any modified files to carry prominent notices
-          stating that You changed the files; and
-
-      (c) You must retain, in the Source form of any Derivative Works
-          that You distribute, all copyright, patent, trademark, and
-          attribution notices from the Source form of the Work,
-          excluding those notices that do not pertain to any part of
-          the Derivative Works; and
-
-      (d) If the Work includes a "NOTICE" text file as part of its
-          distribution, then any Derivative Works that You distribute must
-          include a readable copy of the attribution notices contained
-          within such NOTICE file, excluding those notices that do not
-          pertain to any part of the Derivative Works, in at least one
-          of the following places: within a NOTICE text file distributed
-          as part of the Derivative Works; within the Source form or
-          documentation, if provided along with the Derivative Works; or,
-          within a display generated by the Derivative Works, if and
-          wherever such third-party notices normally appear. The contents
-          of the NOTICE file are for informational purposes only and
-          do not modify the License. You may add Your own attribution
-          notices within Derivative Works that You distribute, alongside
-          or as an addendum to the NOTICE text from the Work, provided
-          that such additional attribution notices cannot be construed
-          as modifying the License.
-
-      You may add Your own copyright statement to Your modifications and
-      may provide additional or different license terms and conditions
-      for use, reproduction, or distribution of Your modifications, or
-      for any such Derivative Works as a whole, provided Your use,
-      reproduction, and distribution of the Work otherwise complies with
-      the conditions stated in this License.
-
-   5. Submission of Contributions. Unless You explicitly state otherwise,
-      any Contribution intentionally submitted for inclusion in the Work
-      by You to the Licensor shall be under the terms and conditions of
-      this License, without any additional terms or conditions.
-      Notwithstanding the above, nothing herein shall supersede or modify
-      the terms of any separate license agreement you may have executed
-      with Licensor regarding such Contributions.
-
-   6. Trademarks. This License does not grant permission to use the trade
-      names, trademarks, service marks, or product names of the Licensor,
-      except as required for reasonable and customary use in describing the
-      origin of the Work and reproducing the content of the NOTICE file.
-
-   7. Disclaimer of Warranty. Unless required by applicable law or
-      agreed to in writing, Licensor provides the Work (and each
-      Contributor provides its Contributions) on an "AS IS" BASIS,
-      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-      implied, including, without limitation, any warranties or conditions
-      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
-      PARTICULAR PURPOSE. You are solely responsible for determining the
-      appropriateness of using or redistributing the Work and assume any
-      risks associated with Your exercise of permissions under this License.
-
-   8. Limitation of Liability. In no event and under no legal theory,
-      whether in tort (including negligence), contract, or otherwise,
-      unless required by applicable law (such as deliberate and grossly
-      negligent acts) or agreed to in writing, shall any Contributor be
-      liable to You for damages, including any direct, indirect, special,
-      incidental, or consequential damages of any character arising as a
-      result of this License or out of the use or inability to use the
-      Work (including but not limited to damages for loss of goodwill,
-      work stoppage, computer failure or malfunction, or any and all
-      other commercial damages or losses), even if such Contributor
-      has been advised of the possibility of such damages.
-
-   9. Accepting Warranty or Additional Liability. While redistributing
-      the Work or Derivative Works thereof, You may choose to offer,
-      and charge a fee for, acceptance of support, warranty, indemnity,
-      or other liability obligations and/or rights consistent with this
-      License. However, in accepting such obligations, You may act only
-      on Your own behalf and on Your sole responsibility, not on behalf
-      of any other Contributor, and only if You agree to indemnify,
-      defend, and hold each Contributor harmless for any liability
-      incurred by, or claims asserted against, such Contributor by reason
-      of your accepting any such warranty or additional liability.
-
-   END OF TERMS AND CONDITIONS
-
-   APPENDIX: How to apply the Apache License to your work.
-
-      To apply the Apache License to your work, attach the following
-      boilerplate notice, with the fields enclosed by brackets "[]"
-      replaced with your own identifying information. (Don't include
-      the brackets!)  The text should be enclosed in the appropriate
-      comment syntax for the file format. We also recommend that a
-      file or class name and description of purpose be included on the
-      same "printed page" as the copyright notice for easier
-      identification within third-party archives.
-
-   Copyright [yyyy] [name of copyright owner]
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/pom.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate/pom.xml b/modules/hibernate/pom.xml
deleted file mode 100644
index 75dacb1..0000000
--- a/modules/hibernate/pom.xml
+++ /dev/null
@@ -1,146 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one or more
-  contributor license agreements.  See the NOTICE file distributed with
-  this work for additional information regarding copyright ownership.
-  The ASF licenses this file to You under the Apache License, Version 2.0
-  (the "License"); you may not use this file except in compliance with
-  the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-
-<!--
-    POM file.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-
-    <parent>
-        <groupId>org.apache.ignite</groupId>
-        <artifactId>ignite-parent</artifactId>
-        <version>1</version>
-        <relativePath>../../parent</relativePath>
-    </parent>
-
-    <artifactId>ignite-hibernate</artifactId>
-    <version>2.0.0-SNAPSHOT</version>
-    <url>http://ignite.apache.org</url>
-
-    <dependencies>
-        <dependency>
-            <groupId>org.apache.ignite</groupId>
-            <artifactId>ignite-core</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.hibernate</groupId>
-            <artifactId>hibernate-core</artifactId>
-            <version>4.2.6.Final</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.ignite</groupId>
-            <artifactId>ignite-jta</artifactId>
-            <version>${project.version}</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.ow2.jotm</groupId>
-            <artifactId>jotm-core</artifactId>
-            <version>2.1.9</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>commons-dbcp</groupId>
-            <artifactId>commons-dbcp</artifactId>
-            <version>1.4</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>com.h2database</groupId>
-            <artifactId>h2</artifactId>
-            <version>${h2.version}</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>javax.resource</groupId>
-            <artifactId>connector-api</artifactId>
-            <version>1.5</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.ignite</groupId>
-            <artifactId>ignite-core</artifactId>
-            <version>${project.version}</version>
-            <type>test-jar</type>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.ignite</groupId>
-            <artifactId>ignite-spring</artifactId>
-            <version>${project.version}</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.ignite</groupId>
-            <artifactId>ignite-log4j</artifactId>
-            <version>${project.version}</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.springframework</groupId>
-            <artifactId>spring-beans</artifactId>
-            <version>${spring.version}</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.springframework</groupId>
-            <artifactId>spring-context</artifactId>
-            <version>${spring.version}</version>
-            <scope>test</scope>
-        </dependency>
-    </dependencies>
-
-    <build>
-        <testResources>
-            <testResource>
-                <directory>src/main/java</directory>
-                <excludes>
-                    <exclude>**/*.java</exclude>
-                </excludes>
-            </testResource>
-            <testResource>
-                <directory>src/test/java</directory>
-                <excludes>
-                    <exclude>**/*.java</exclude>
-                </excludes>
-            </testResource>
-        </testResources>
-
-        <plugins>
-            <!-- Generate the OSGi MANIFEST.MF for this bundle. -->
-            <plugin>
-                <groupId>org.apache.felix</groupId>
-                <artifactId>maven-bundle-plugin</artifactId>
-            </plugin>
-        </plugins>
-    </build>
-</project>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateAbstractRegionAccessStrategy.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateAbstractRegionAccessStrategy.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateAbstractRegionAccessStrategy.java
deleted file mode 100644
index 7186cfb..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateAbstractRegionAccessStrategy.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.access.RegionAccessStrategy;
-import org.hibernate.cache.spi.access.SoftLock;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Implementation of L2 cache access strategy delegating to {@link HibernateAccessStrategyAdapter}.
- */
-public abstract class HibernateAbstractRegionAccessStrategy implements RegionAccessStrategy {
-    /** */
-    protected final HibernateAccessStrategyAdapter stgy;
-
-    /**
-     * @param stgy Access strategy implementation.
-     */
-    protected HibernateAbstractRegionAccessStrategy(HibernateAccessStrategyAdapter stgy) {
-        this.stgy = stgy;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object get(Object key, long txTs) throws CacheException {
-        return stgy.get(key);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean putFromLoad(Object key, Object val, long txTs, Object ver) throws CacheException {
-        stgy.putFromLoad(key, val);
-
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean putFromLoad(Object key, Object val, long txTs, Object ver, boolean minimalPutOverride)
-        throws CacheException {
-        stgy.putFromLoad(key, val, minimalPutOverride);
-
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public SoftLock lockItem(Object key, Object ver) throws CacheException {
-        return stgy.lock(key);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public SoftLock lockRegion() throws CacheException {
-        return stgy.lockRegion();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unlockRegion(SoftLock lock) throws CacheException {
-        stgy.unlockRegion(lock);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unlockItem(Object key, SoftLock lock) throws CacheException {
-        stgy.unlock(key, lock);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void remove(Object key) throws CacheException {
-        stgy.remove(key);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void removeAll() throws CacheException {
-        stgy.removeAll();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void evict(Object key) throws CacheException {
-        stgy.evict(key);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void evictAll() throws CacheException {
-        stgy.evictAll();
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyAdapter.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyAdapter.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyAdapter.java
deleted file mode 100644
index f6c1d0e..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyAdapter.java
+++ /dev/null
@@ -1,379 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteCallable;
-import org.apache.ignite.resources.IgniteInstanceResource;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
-import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
-import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy;
-import org.hibernate.cache.spi.access.RegionAccessStrategy;
-import org.hibernate.cache.spi.access.SoftLock;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Common interface used to implement Hibernate L2 cache access strategies ({@link RegionAccessStrategy},
- * {@link EntityRegionAccessStrategy} and {@link CollectionRegionAccessStrategy}).
- * <p>
- * The expected sequences of steps related to various CRUD operations executed by Hibernate are:
- * <p>
- * Insert:
- * <ul>
- *     <li>Start DB transaction.</li>
- *     <li>Execute database insert.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#insert}.</li>
- *     <li>Commit DB transaction.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#afterInsert}.</li>
- * </ul>
- * In case if some step fails and DB transaction is rolled back then
- * {@link HibernateAccessStrategyAdapter#afterInsert} is not called.
- * <p>
- * Update:
- * <ul>
- *     <li>Start DB transaction.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#lock}.</li>
- *     <li>Execute database update.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#update}.</li>
- *     <li>Commit DB transaction.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#afterUpdate}.</li>
- * </ul>
- * In case if {@link HibernateAccessStrategyAdapter#lock} was called, but some other step fails and DB
- * transaction is rolled back then {@link HibernateAccessStrategyAdapter#unlock} is called for all locked keys.
- * <p>
- * Delete:
- * <ul>
- *     <li>Start DB transaction.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#lock} for removing key.</li>
- *     <li>Execute database delete.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#remove}.</li>
- *     <li>Commit DB transaction.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#unlock}.</li>
- * </ul>
- * In case if {@link HibernateAccessStrategyAdapter#lock} was called, but some other step fails and DB
- * transaction is rolled back then {@link HibernateAccessStrategyAdapter#unlock} is called for all locked keys.
- * <p>
- * In case if custom SQL update query is executed Hibernate clears entire cache region,
- * for this case operations sequence is:
- * <ul>
- *     <li>Start DB transaction.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#lockRegion}.</li>
- *     <li>Execute database query.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#removeAll}.</li>
- *     <li>Commit DB transaction.</li>
- *     <li>Call {@link HibernateAccessStrategyAdapter#unlockRegion}.</li>
- * </ul>
- */
-public abstract class HibernateAccessStrategyAdapter {
-    /** */
-    protected final HibernateCacheProxy cache;
-
-    /** Grid. */
-    protected final Ignite ignite;
-
-    /** */
-    protected final IgniteLogger log;
-
-    /**
-     * @param ignite Grid.
-     * @param cache Cache.
-     */
-    protected HibernateAccessStrategyAdapter(Ignite ignite, HibernateCacheProxy cache) {
-        this.cache = cache;
-        this.ignite = ignite;
-
-        log = ignite.log();
-    }
-
-    /**
-     * Gets value from cache. Used by {@link RegionAccessStrategy#get}.
-     *
-     * @param key Key.
-     * @return Cached value.
-     * @throws CacheException If failed.
-     */
-    @Nullable protected Object get(Object key) throws CacheException {
-        try {
-            return cache.get(key);
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /**
-     * Puts in cache value loaded from the database. Used by {@link RegionAccessStrategy#putFromLoad}.
-     *
-     * @param key Key.
-     * @param val Value.
-     * @param minimalPutOverride MinimalPut flag
-     * @throws CacheException If failed.
-     */
-    protected void putFromLoad(Object key, Object val, boolean minimalPutOverride) throws CacheException {
-        putFromLoad(key, val);
-    }
-
-    /**
-     * Puts in cache value loaded from the database. Used by {@link RegionAccessStrategy#putFromLoad}.
-     *
-     * @param key Key.
-     * @param val Value.
-     * @throws CacheException If failed.
-     */
-    protected void putFromLoad(Object key, Object val) throws CacheException {
-        try {
-            cache.put(key, val);
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /**
-     * Called during database transaction execution before Hibernate attempts to update or remove given key.
-     * Used by {@link RegionAccessStrategy#lockItem}.
-     *
-     * @param key Key.
-     * @return Lock representation or {@code null}.
-     * @throws CacheException If failed.
-     */
-    @Nullable protected abstract SoftLock lock(Object key) throws CacheException;
-
-    /**
-     * Called after Hibernate failed to update or successfully removed given key.
-     * Used by {@link RegionAccessStrategy#unlockItem}.
-     *
-     * @param key Key.
-     * @param lock The lock previously obtained from {@link #lock}
-     * @throws CacheException If failed.
-     */
-    protected abstract void unlock(Object key, SoftLock lock) throws CacheException;
-
-    /**
-     * Called after Hibernate updated object in the database but before transaction completed.
-     * Used by {@link EntityRegionAccessStrategy#update} and {@link NaturalIdRegionAccessStrategy#update}.
-     *
-     * @param key Key.
-     * @param val Value.
-     * @return {@code True} if operation updated cache.
-     * @throws CacheException If failed.
-     */
-    protected abstract boolean update(Object key, Object val) throws CacheException;
-
-    /**
-     * Called after Hibernate updated object in the database and transaction successfully completed.
-     * Used by {@link EntityRegionAccessStrategy#afterUpdate} and {@link NaturalIdRegionAccessStrategy#afterUpdate}.
-     *
-     * @param key Key.
-     * @param val Value.
-     * @param lock The lock previously obtained from {@link #lock}
-     * @return {@code True} if operation updated cache.
-     * @throws CacheException If failed.
-     */
-    protected abstract boolean afterUpdate(Object key, Object val, SoftLock lock) throws CacheException;
-
-    /**
-     * Called after Hibernate inserted object in the database but before transaction completed.
-     * Used by {@link EntityRegionAccessStrategy#insert} and {@link NaturalIdRegionAccessStrategy#insert}.
-     *
-     * @param key Key.
-     * @param val Value.
-     * @return {@code True} if operation updated cache.
-     * @throws CacheException If failed.
-     */
-    protected abstract boolean insert(Object key, Object val) throws CacheException;
-
-    /**
-     * Called after Hibernate inserted object in the database and transaction successfully completed.
-     * Used by {@link EntityRegionAccessStrategy#afterInsert} and {@link NaturalIdRegionAccessStrategy#afterInsert}.
-     *
-     * @param key Key.
-     * @param val Value.
-     * @return {@code True} if operation updated cache.
-     * @throws CacheException If failed.
-     */
-    protected abstract boolean afterInsert(Object key, Object val) throws CacheException;
-
-    /**
-     * Called after Hibernate removed object from database but before transaction completed.
-     * Used by {@link RegionAccessStrategy#remove}.
-     *
-     * @param key Key,
-     * @throws CacheException If failed.
-     */
-    protected abstract void remove(Object key) throws CacheException;
-
-    /**
-     * Called to remove object from cache without regard to transaction.
-     * Used by {@link RegionAccessStrategy#evict}.
-     *
-     * @param key Key.
-     * @throws CacheException If failed.
-     */
-    protected void evict(Object key) throws CacheException {
-        evict(ignite, cache, key);
-    }
-
-    /**
-     * Called to remove all data from cache without regard to transaction.
-     * Used by {@link RegionAccessStrategy#evictAll}.
-     *
-     * @throws CacheException If failed.
-     */
-    protected void evictAll() throws CacheException {
-        evictAll(cache);
-    }
-
-    /**
-     * Called during database transaction execution before Hibernate executed
-     * update operation which should invalidate entire cache region.
-     * Used by {@link RegionAccessStrategy#lockRegion}.
-     *
-     * @throws CacheException If failed.
-     * @return Lock representation or {@code null}.
-     */
-    @Nullable protected SoftLock lockRegion() throws CacheException {
-        return null;
-    }
-
-    /**
-     * Called after transaction clearing entire cache region completed.
-     * Used by {@link RegionAccessStrategy#unlockRegion}.
-     *
-     * @param lock The lock previously obtained from {@link #lockRegion}
-     * @throws CacheException If failed.
-     */
-    protected void unlockRegion(SoftLock lock) throws CacheException {
-        // No-op.
-    }
-
-    /**
-     * Called during database transaction execution to clear entire cache region after
-     * Hibernate executed database update, but before transaction completed.
-     * Used by {@link RegionAccessStrategy#removeAll}.
-     *
-     * @throws CacheException If failed.
-     */
-    protected final void removeAll() throws CacheException {
-        evictAll();
-    }
-
-    /**
-     * Called to remove object from cache without regard to transaction.
-     *
-     * @param ignite Grid.
-     * @param cache Cache.
-     * @param key Key.
-     * @throws CacheException If failed.
-     */
-    static void evict(Ignite ignite, HibernateCacheProxy cache, Object key) throws CacheException {
-        try {
-            key = cache.keyTransformer().transform(key);
-
-            ignite.compute(ignite.cluster()).call(new ClearKeyCallable(key, cache.name()));
-        }
-        catch (IgniteException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /**
-     * Called to remove all data from cache without regard to transaction.
-     *
-     * @param cache Cache.
-     * @throws CacheException If failed.
-     */
-    static void evictAll(IgniteInternalCache<Object,Object> cache) throws CacheException {
-        try {
-            cache.clear();
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /**
-     * Callable invalidates given key.
-     */
-    private static class ClearKeyCallable implements IgniteCallable<Void>, Externalizable {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /** */
-        @IgniteInstanceResource
-        private Ignite ignite;
-
-        /** */
-        private Object key;
-
-        /** */
-        private String cacheName;
-
-        /**
-         * Empty constructor required by {@link Externalizable}.
-         */
-        public ClearKeyCallable() {
-            // No-op.
-        }
-
-        /**
-         * @param key Key to clear.
-         * @param cacheName Cache name.
-         */
-        private ClearKeyCallable(Object key, String cacheName) {
-            this.key = key;
-            this.cacheName = cacheName;
-        }
-
-        /** {@inheritDoc} */
-        @Override public Void call() throws IgniteCheckedException {
-            IgniteInternalCache<Object, Object> cache = ((IgniteKernal)ignite).getCache(cacheName);
-
-            assert cache != null;
-
-            cache.clearLocally(key);
-
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            out.writeObject(key);
-
-            U.writeString(out, cacheName);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            key = in.readObject();
-
-            cacheName = U.readString(in);
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateCacheProxy.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateCacheProxy.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateCacheProxy.java
deleted file mode 100644
index 7204083..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateCacheProxy.java
+++ /dev/null
@@ -1,801 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import javax.cache.Cache;
-import javax.cache.expiry.ExpiryPolicy;
-import javax.cache.processor.EntryProcessor;
-import javax.cache.processor.EntryProcessorResult;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.cache.CacheEntry;
-import org.apache.ignite.cache.CacheMetrics;
-import org.apache.ignite.cache.CachePeekMode;
-import org.apache.ignite.cache.affinity.Affinity;
-import org.apache.ignite.cluster.ClusterGroup;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
-import org.apache.ignite.internal.processors.cache.CacheEntryPredicate;
-import org.apache.ignite.internal.processors.cache.GridCacheContext;
-import org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy;
-import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
-import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
-import org.apache.ignite.lang.IgniteBiPredicate;
-import org.apache.ignite.mxbean.CacheMetricsMXBean;
-import org.apache.ignite.transactions.Transaction;
-import org.apache.ignite.transactions.TransactionConcurrency;
-import org.apache.ignite.transactions.TransactionIsolation;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Hibernate cache proxy used to substitute hibernate keys with ignite keys.
- */
-public class HibernateCacheProxy implements IgniteInternalCache<Object, Object> {
-    /** Delegate. */
-    private final IgniteInternalCache<Object, Object> delegate;
-
-    /** Transformer. */
-    private final HibernateKeyTransformer keyTransformer;
-
-    /**
-     * @param delegate Delegate.
-     * @param keyTransformer Key keyTransformer.
-     */
-    HibernateCacheProxy(
-        IgniteInternalCache<Object, Object> delegate,
-        HibernateKeyTransformer keyTransformer
-    ) {
-        assert delegate != null;
-        assert keyTransformer != null;
-
-        this.delegate = delegate;
-        this.keyTransformer = keyTransformer;
-    }
-
-    /**
-     * @return HibernateKeyTransformer
-     */
-    HibernateKeyTransformer keyTransformer(){
-        return keyTransformer;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String name() {
-        return delegate.name();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean skipStore() {
-        return delegate.skipStore();
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalCache setSkipStore(boolean skipStore) {
-        return delegate.setSkipStore(skipStore);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isEmpty() {
-        return delegate.isEmpty();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean containsKey(Object key) {
-        return delegate.containsKey(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> containsKeyAsync(Object key) {
-        return delegate.containsKeyAsync(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean containsKeys(Collection keys) {
-        return delegate.containsKey(transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> containsKeysAsync(Collection keys) {
-        return delegate.containsKeysAsync(transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object localPeek(
-        Object key,
-        CachePeekMode[] peekModes,
-        @Nullable IgniteCacheExpiryPolicy plc
-    ) throws IgniteCheckedException {
-        return delegate.localPeek(keyTransformer.transform(key), peekModes, plc);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Iterable<Cache.Entry<Object, Object>> localEntries(
-        CachePeekMode[] peekModes
-    ) throws IgniteCheckedException {
-        return delegate.localEntries(peekModes);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object get(Object key) throws IgniteCheckedException {
-        return delegate.get(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public CacheEntry getEntry(Object key) throws IgniteCheckedException {
-        return delegate.getEntry(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture getAsync(Object key) {
-        return delegate.getAsync(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<CacheEntry<Object, Object>> getEntryAsync(Object key) {
-        return delegate.getEntryAsync(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Map getAll(@Nullable Collection keys) throws IgniteCheckedException {
-        return delegate.getAll(transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<CacheEntry<Object, Object>> getEntries(
-        @Nullable Collection keys) throws IgniteCheckedException {
-        return delegate.getEntries(transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Map<Object, Object>> getAllAsync(@Nullable Collection keys) {
-        return delegate.getAllAsync(transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Collection<CacheEntry<Object,Object>>> getEntriesAsync(
-        @Nullable Collection keys
-    ) {
-        return delegate.getEntriesAsync(transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object getAndPut(Object key, Object val) throws IgniteCheckedException {
-        return delegate.getAndPut(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture getAndPutAsync(Object key, Object val) {
-        return delegate.getAndPutAsync(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean put(Object key, Object val) throws IgniteCheckedException {
-        return delegate.put(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> putAsync(Object key, Object val) {
-        return delegate.putAsync(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object getAndPutIfAbsent(Object key, Object val) throws IgniteCheckedException {
-        return delegate.getAndPutIfAbsent(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture getAndPutIfAbsentAsync(Object key, Object val) {
-        return delegate.getAndPutIfAbsentAsync(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean putIfAbsent(Object key, Object val) throws IgniteCheckedException {
-        return delegate.putIfAbsent(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> putIfAbsentAsync(Object key, Object val) {
-        return delegate.putIfAbsentAsync(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object getAndReplace(Object key, Object val) throws IgniteCheckedException {
-        return delegate.getAndReplace(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture getAndReplaceAsync(Object key, Object val) {
-        return delegate.getAndReplaceAsync(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean replace(Object key, Object val) throws IgniteCheckedException {
-        return delegate.replace(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> replaceAsync(Object key, Object val) {
-        return delegate.replaceAsync(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean replace(Object key, Object oldVal, Object newVal) throws IgniteCheckedException {
-        return delegate.replace(keyTransformer.transform(key), oldVal, newVal);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> replaceAsync(Object key, Object oldVal, Object newVal) {
-        return delegate.replaceAsync(keyTransformer.transform(key), oldVal, newVal);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void putAll(@Nullable Map m) throws IgniteCheckedException {
-        delegate.putAll(transform(m));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<?> putAllAsync(@Nullable Map m) {
-        return delegate.putAllAsync(transform(m));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Set keySet() {
-        return delegate.keySet();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Set keySetx() {
-        return delegate.keySetx();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Set primaryKeySet() {
-        return delegate.primaryKeySet();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Iterable values() {
-        return delegate.values();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Set<Cache.Entry<Object, Object>> entrySet() {
-        return delegate.entrySet();
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Set<Cache.Entry<Object,Object>> entrySet(int part) {
-        return delegate.entrySet(part);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Set<Cache.Entry<Object, Object>> entrySetx(CacheEntryPredicate... filter) {
-        return delegate.entrySetx(filter);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Transaction txStart(
-        TransactionConcurrency concurrency,
-        TransactionIsolation isolation
-    ) {
-        return delegate.txStart(concurrency, isolation);
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridNearTxLocal txStartEx(
-        TransactionConcurrency concurrency,
-        TransactionIsolation isolation
-    ) {
-        return delegate.txStartEx(concurrency, isolation);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Transaction txStart(
-        TransactionConcurrency concurrency,
-        TransactionIsolation isolation,
-        long timeout,
-        int txSize
-    ) {
-        return delegate.txStart(concurrency, isolation, timeout, txSize);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public GridNearTxLocal tx() {
-        return delegate.tx();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean evict(Object key) {
-        return delegate.evict(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void evictAll(@Nullable Collection keys) {
-        delegate.evictAll(transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void clearLocally(boolean srv, boolean near, boolean readers) {
-        delegate.clearLocally(srv, near, readers);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean clearLocally(Object key) {
-        return delegate.clearLocally(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void clearLocallyAll(Set keys, boolean srv, boolean near, boolean readers) {
-        delegate.clearLocallyAll((Set<?>)transform(keys), srv, near, readers);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void clear(Object key) throws IgniteCheckedException {
-        delegate.clear(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void clearAll(Set keys) throws IgniteCheckedException {
-        delegate.clearAll((Set<?>)transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void clear() throws IgniteCheckedException {
-        delegate.clear();
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<?> clearAsync() {
-        return delegate.clearAsync();
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<?> clearAsync(Object key) {
-        return delegate.clearAsync(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<?> clearAllAsync(Set keys) {
-        return delegate.clearAllAsync((Set<?>)transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object getAndRemove(Object key) throws IgniteCheckedException {
-        return delegate.getAndRemove(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture getAndRemoveAsync(Object key) {
-        return delegate.getAndRemoveAsync(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean remove(Object key) throws IgniteCheckedException {
-        return delegate.remove(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> removeAsync(Object key) {
-        return delegate.removeAsync(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean remove(Object key, Object val) throws IgniteCheckedException {
-        return delegate.remove(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> removeAsync(Object key, Object val) {
-        return delegate.removeAsync(keyTransformer.transform(key), val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void removeAll(@Nullable Collection keys) throws IgniteCheckedException {
-        delegate.removeAll(transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<?> removeAllAsync(@Nullable Collection keys) {
-        return delegate.removeAllAsync(transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void removeAll() throws IgniteCheckedException {
-        delegate.removeAll();
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<?> removeAllAsync() {
-        return delegate.removeAllAsync();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean lock(Object key, long timeout) throws IgniteCheckedException {
-        return delegate.lock(keyTransformer.transform(key), timeout);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> lockAsync(Object key, long timeout) {
-        return delegate.lockAsync(keyTransformer.transform(key), timeout);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean lockAll(@Nullable Collection keys, long timeout) throws IgniteCheckedException {
-        return delegate.lockAll(transform(keys), timeout);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> lockAllAsync(@Nullable Collection keys, long timeout) {
-        return delegate.lockAllAsync(transform(keys), timeout);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unlock(Object key) throws IgniteCheckedException {
-        delegate.unlock(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unlockAll(@Nullable Collection keys) throws IgniteCheckedException {
-        delegate.unlockAll(transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isLocked(Object key) {
-        return delegate.isLocked(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isLockedByThread(Object key) {
-        return delegate.isLockedByThread(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        return delegate.size();
-    }
-
-    /** {@inheritDoc} */
-    @Override public long sizeLong() {
-        return delegate.sizeLong();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int localSize(CachePeekMode[] peekModes) throws IgniteCheckedException {
-        return delegate.localSize(peekModes);
-    }
-
-    /** {@inheritDoc} */
-    @Override public long localSizeLong(CachePeekMode[] peekModes) throws IgniteCheckedException {
-        return delegate.localSizeLong(peekModes);
-    }
-
-    /** {@inheritDoc} */
-    @Override public long localSizeLong(int partition, CachePeekMode[] peekModes) throws IgniteCheckedException {
-        return delegate.localSizeLong(partition, peekModes);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size(CachePeekMode[] peekModes) throws IgniteCheckedException {
-        return delegate.size(peekModes);
-    }
-
-    /** {@inheritDoc} */
-    @Override public long sizeLong(CachePeekMode[] peekModes) throws IgniteCheckedException {
-        return delegate.sizeLong(peekModes);
-    }
-
-    /** {@inheritDoc} */
-    @Override public long sizeLong(int partition, CachePeekMode[] peekModes) throws IgniteCheckedException {
-        return delegate.sizeLong(partition, peekModes);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Integer> sizeAsync(CachePeekMode[] peekModes) {
-        return delegate.sizeAsync(peekModes);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Long> sizeLongAsync(CachePeekMode[] peekModes) {
-        return delegate.sizeLongAsync(peekModes);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Long> sizeLongAsync(int partition, CachePeekMode[] peekModes) {
-        return delegate.sizeLongAsync(partition, peekModes);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int nearSize() {
-        return delegate.nearSize();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int primarySize() {
-        return delegate.primarySize();
-    }
-
-    /** {@inheritDoc} */
-    @Override public long primarySizeLong() {
-        return delegate.primarySizeLong();
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheConfiguration configuration() {
-        return delegate.configuration();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Affinity affinity() {
-        return delegate.affinity();
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheMetrics clusterMetrics() {
-        return delegate.clusterMetrics();
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheMetrics clusterMetrics(ClusterGroup grp) {
-        return delegate.clusterMetrics(grp);
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheMetrics localMetrics() {
-        return delegate.localMetrics();
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheMetricsMXBean clusterMxBean() {
-        return delegate.clusterMxBean();
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheMetricsMXBean localMxBean() {
-        return delegate.localMxBean();
-    }
-
-    /** {@inheritDoc} */
-    @Override public long offHeapEntriesCount() {
-        return delegate.offHeapEntriesCount();
-    }
-
-    /** {@inheritDoc} */
-    @Override public long offHeapAllocatedSize() {
-        return delegate.offHeapAllocatedSize();
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<?> rebalance() {
-        return delegate.rebalance();
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalCache forSubjectId(UUID subjId) {
-        return delegate.forSubjectId(subjId);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object getForcePrimary(Object key) throws IgniteCheckedException {
-        return delegate.getForcePrimary(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture getForcePrimaryAsync(Object key) {
-        return delegate.getForcePrimaryAsync(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Map getAllOutTx(Set keys) throws IgniteCheckedException {
-        return delegate.getAllOutTx((Set<?>)transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Map<Object, Object>> getAllOutTxAsync(Set keys) {
-        return delegate.getAllOutTxAsync((Set<?>)transform(keys));
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isIgfsDataCache() {
-        return delegate.isIgfsDataCache();
-    }
-
-    /** {@inheritDoc} */
-    @Override public long igfsDataSpaceUsed() {
-        return delegate.igfsDataSpaceUsed();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isMongoDataCache() {
-        return delegate.isMongoDataCache();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isMongoMetaCache() {
-        return delegate.isMongoMetaCache();
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public ExpiryPolicy expiry() {
-        return delegate.expiry();
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalCache withExpiryPolicy(ExpiryPolicy plc) {
-        return delegate.withExpiryPolicy(plc);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalCache withNoRetries() {
-        return delegate.withNoRetries();
-    }
-
-    /** {@inheritDoc} */
-    @Override public GridCacheContext context() {
-        return delegate.context();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void localLoadCache(
-        @Nullable IgniteBiPredicate p,
-        @Nullable Object... args
-    ) throws IgniteCheckedException {
-        delegate.localLoadCache(p, args);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<?> localLoadCacheAsync(
-        @Nullable IgniteBiPredicate p,
-        @Nullable Object... args
-    ) {
-        return delegate.localLoadCacheAsync(p, args);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object getTopologySafe(Object key) throws IgniteCheckedException {
-        return delegate.getTopologySafe(keyTransformer.transform(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<Integer> lostPartitions() {
-        return delegate.lostPartitions();
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public EntryProcessorResult invoke(
-        @Nullable AffinityTopologyVersion topVer,
-        Object key,
-        EntryProcessor entryProcessor,
-        Object... args
-    ) throws IgniteCheckedException {
-        return delegate.invoke(topVer, key, entryProcessor, args);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Map> invokeAllAsync(Map map, Object... args) {
-        return delegate.invokeAllAsync(map, args);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Map invokeAll(Map map, Object... args) throws IgniteCheckedException {
-        return delegate.invokeAll(map, args);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Map> invokeAllAsync(Set keys, EntryProcessor entryProcessor, Object... args) {
-        return delegate.invokeAllAsync((Set<?>)transform(keys), entryProcessor, args);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Map invokeAll(Set keys, EntryProcessor entryProcessor, Object... args) throws IgniteCheckedException {
-        return delegate.invokeAll((Set<?>)transform(keys), entryProcessor, args);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<EntryProcessorResult> invokeAsync(
-        Object key,
-        EntryProcessor entryProcessor,
-        Object... args
-    ) {
-        return delegate.invokeAsync(keyTransformer.transform(key), entryProcessor, args);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public EntryProcessorResult invoke(
-        Object key,
-        EntryProcessor entryProcessor,
-        Object... args
-    ) throws IgniteCheckedException {
-        return delegate.invoke(keyTransformer.transform(key), entryProcessor, args);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Iterator<Cache.Entry<Object,Object>> scanIterator(
-        boolean keepBinary,
-        @Nullable IgniteBiPredicate p
-    ) throws IgniteCheckedException {
-        return delegate.scanIterator(keepBinary, p);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<?> removeAllConflictAsync(Map drMap) throws IgniteCheckedException {
-        return delegate.removeAllConflictAsync(drMap);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void removeAllConflict(Map drMap) throws IgniteCheckedException {
-        delegate.removeAllConflictAsync(drMap);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<?> putAllConflictAsync(Map drMap) throws IgniteCheckedException {
-        return delegate.putAllConflictAsync(drMap);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void putAllConflict(Map drMap) throws IgniteCheckedException {
-        delegate.putAllConflict(drMap);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalCache keepBinary() {
-        return delegate.keepBinary();
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalCache cache() {
-        return delegate.cache();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Iterator iterator() {
-        return delegate.iterator();
-    }
-
-    /**
-     * @param keys Keys.
-     */
-    private Collection<Object> transform(Collection<Object> keys) {
-        Collection<Object> res = new LinkedList<>();
-
-        for (Object o : keys)
-            res.add(keyTransformer.transform(o));
-
-        return res;
-    }
-
-    /**
-     * @param map Map.
-     */
-    private Map<Object, Object> transform(Map<Object, Object> map) {
-        Map<Object, Object> res = new HashMap<>();
-
-        Set<Map.Entry<Object, Object>> ents = map.entrySet();
-
-        for (Map.Entry<Object, Object> e : ents)
-            res.put(keyTransformer.transform(e.getKey()), e.getValue());
-
-        return res;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java
deleted file mode 100644
index eb35a2c..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.apache.ignite.Ignite;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.CacheDataDescription;
-import org.hibernate.cache.spi.CollectionRegion;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
-
-/**
- * Implementation of {@link CollectionRegion}. This region is used to store collection data.
- * <p>
- * L2 cache for collection can be enabled in the Hibernate configuration file:
- * <pre name="code" class="xml">
- * &lt;hibernate-configuration&gt;
- *     &lt;!-- Enable L2 cache. --&gt;
- *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
- *
- *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
- *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
- *
- *     &lt;!-- Specify entities. --&gt;
- *     &lt;mapping class="com.example.Entity"/&gt;
- *     &lt;mapping class="com.example.ChildEntity"/&gt;
- *
- *     &lt;!-- Enable L2 cache with nonstrict-read-write access strategy for entities and collection. --&gt;
- *     &lt;collection-cache collection="com.example.Entity" usage="nonstrict-read-write"/&gt;
- *     &lt;collection-cache collection="com.example.ChildEntity" usage="nonstrict-read-write"/&gt;
- *     &lt;collection-cache collection="com.example.Entity.children" usage="nonstrict-read-write"/&gt;
- * &lt;/hibernate-configuration&gt;
- * </pre>
- * Also cache for collection can be enabled using annotations:
- * <pre name="code" class="java">
- * &#064;javax.persistence.Entity
- * public class Entity {
- *    ...
- *
- *    &#064;javax.persistence.OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
- *    &#064;javax.persistence.JoinColumn(name="PARENT_ID")
- *    &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
- *    public List&lt;ChildEntity&gt; getChildren() {...}
- * }
- * </pre>
- * Note: the collection cache does not cache the state of the actual entities in the cache, it caches only identifier
- * values. For this reason, the collection cache should always be used in conjunction with
- * the second-level cache for those entities expected to be cached as part of a collection cache.
- */
-public class HibernateCollectionRegion extends HibernateTransactionalDataRegion implements CollectionRegion {
-    /**
-     * @param factory Region factory.
-     * @param name Region name.
-     * @param ignite Grid.
-     * @param cache Region cache.
-     * @param dataDesc Region data description.
-     */
-    public HibernateCollectionRegion(HibernateRegionFactory factory, String name,
-        Ignite ignite, HibernateCacheProxy cache, CacheDataDescription dataDesc) {
-        super(factory, name, ignite, cache, dataDesc);
-    }
-
-    /** {@inheritDoc} */
-    @Override public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
-        return new AccessStrategy(createAccessStrategy(accessType));
-    }
-
-    /**
-     * Collection region access strategy.
-     */
-    private class AccessStrategy extends HibernateAbstractRegionAccessStrategy
-        implements CollectionRegionAccessStrategy {
-        /**
-         * @param stgy Access strategy implementation.
-         */
-        private AccessStrategy(HibernateAccessStrategyAdapter stgy) {
-            super(stgy);
-        }
-
-        /** {@inheritDoc} */
-        @Override public CollectionRegion getRegion() {
-            return HibernateCollectionRegion.this;
-        }
-    }
-}
\ No newline at end of file


[10/16] ignite git commit: ignite-1794 Refactored hibernate modules, switched to hibernate 5.1

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListenerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListenerSelfTest.java b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListenerSelfTest.java
new file mode 100644
index 0000000..0010425
--- /dev/null
+++ b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListenerSelfTest.java
@@ -0,0 +1,242 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.store.hibernate;
+
+import java.io.Serializable;
+import java.util.Map;
+import javax.cache.Cache;
+import javax.cache.configuration.Factory;
+import javax.cache.integration.CacheLoaderException;
+import javax.cache.integration.CacheWriterException;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import org.apache.ignite.cache.store.CacheStore;
+import org.apache.ignite.cache.store.CacheStoreAdapter;
+import org.apache.ignite.cache.store.CacheStoreSession;
+import org.apache.ignite.cache.store.CacheStoreSessionListener;
+import org.apache.ignite.cache.store.CacheStoreSessionListenerAbstractSelfTest;
+import org.apache.ignite.cache.store.jdbc.CacheJdbcStoreSessionListener;
+import org.apache.ignite.lang.IgniteBiInClosure;
+import org.apache.ignite.resources.CacheStoreSessionResource;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.resource.transaction.spi.TransactionStatus;
+
+/**
+ * Tests for {@link CacheJdbcStoreSessionListener}.
+ */
+public class CacheHibernateStoreSessionListenerSelfTest extends CacheStoreSessionListenerAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected Factory<? extends CacheStore<Integer, Integer>> storeFactory() {
+        return new Factory<CacheStore<Integer, Integer>>() {
+            @Override public CacheStore<Integer, Integer> create() {
+                return new Store();
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Factory<CacheStoreSessionListener> sessionListenerFactory() {
+        return new Factory<CacheStoreSessionListener>() {
+            @Override public CacheStoreSessionListener create() {
+                CacheHibernateStoreSessionListener lsnr = new CacheHibernateStoreSessionListener();
+
+                SessionFactory sesFactory = new Configuration().
+                    setProperty("hibernate.connection.url", URL).
+                    addAnnotatedClass(Table1.class).
+                    addAnnotatedClass(Table2.class).
+                    buildSessionFactory();
+
+                lsnr.setSessionFactory(sesFactory);
+
+                return lsnr;
+            }
+        };
+    }
+
+    /**
+     */
+    private static class Store extends CacheStoreAdapter<Integer, Integer> {
+        /** */
+        private static String SES_CONN_KEY = "ses_conn";
+
+        /** */
+        @CacheStoreSessionResource
+        private CacheStoreSession ses;
+
+        /** {@inheritDoc} */
+        @Override public void loadCache(IgniteBiInClosure<Integer, Integer> clo, Object... args) {
+            loadCacheCnt.incrementAndGet();
+
+            checkSession();
+        }
+
+        /** {@inheritDoc} */
+        @Override public Integer load(Integer key) throws CacheLoaderException {
+            loadCnt.incrementAndGet();
+
+            checkSession();
+
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void write(Cache.Entry<? extends Integer, ? extends Integer> entry)
+            throws CacheWriterException {
+            writeCnt.incrementAndGet();
+
+            checkSession();
+
+            if (write.get()) {
+                Session hibSes = ses.attachment();
+
+                switch (ses.cacheName()) {
+                    case "cache1":
+                        hibSes.save(new Table1(entry.getKey(), entry.getValue()));
+
+                        break;
+
+                    case "cache2":
+                        if (fail.get())
+                            throw new CacheWriterException("Expected failure.");
+
+                        hibSes.save(new Table2(entry.getKey(), entry.getValue()));
+
+                        break;
+
+                    default:
+                        throw new CacheWriterException("Wring cache: " + ses.cacheName());
+                }
+            }
+        }
+
+        /** {@inheritDoc} */
+        @Override public void delete(Object key) throws CacheWriterException {
+            deleteCnt.incrementAndGet();
+
+            checkSession();
+        }
+
+        /** {@inheritDoc} */
+        @Override public void sessionEnd(boolean commit) {
+            assertNull(ses.attachment());
+        }
+
+        /**
+         */
+        private void checkSession() {
+            Session hibSes = ses.attachment();
+
+            assertNotNull(hibSes);
+
+            assertTrue(hibSes.isOpen());
+
+            Transaction tx = hibSes.getTransaction();
+
+            assertNotNull(tx);
+
+            if (ses.isWithinTransaction())
+                assertEquals(TransactionStatus.ACTIVE, tx.getStatus());
+            else
+                assertFalse("Unexpected status: " + tx.getStatus(), tx.getStatus() == TransactionStatus.ACTIVE);
+
+            verifySameInstance(hibSes);
+        }
+
+        /**
+         * @param hibSes Session.
+         */
+        private void verifySameInstance(Session hibSes) {
+            Map<String, Session> props = ses.properties();
+
+            Session sesConn = props.get(SES_CONN_KEY);
+
+            if (sesConn == null)
+                props.put(SES_CONN_KEY, hibSes);
+            else {
+                assertSame(hibSes, sesConn);
+
+                reuseCnt.incrementAndGet();
+            }
+        }
+    }
+
+    /**
+     */
+    @Entity
+    @Table(name = "Table1")
+    private static class Table1 implements Serializable {
+        /** */
+        @Id
+        @GeneratedValue(strategy = GenerationType.IDENTITY)
+        @Column(name = "id")
+        private Integer id;
+
+        /** */
+        @Column(name = "key")
+        private int key;
+
+        /** */
+        @Column(name = "value")
+        private int value;
+
+        /**
+         * @param key Key.
+         * @param value Value.
+         */
+        private Table1(int key, int value) {
+            this.key = key;
+            this.value = value;
+        }
+    }
+
+    /**
+     */
+    @Entity
+    @Table(name = "Table2")
+    private static class Table2 implements Serializable {
+        /** */
+        @Id
+        @GeneratedValue(strategy = GenerationType.IDENTITY)
+        @Column(name = "id")
+        private Integer id;
+
+        /** */
+        @Column(name = "key")
+        private int key;
+
+        /** */
+        @Column(name = "value")
+        private int value;
+
+        /**
+         * @param key Key.
+         * @param value Value.
+         */
+        private Table2(int key, int value) {
+            this.key = key;
+            this.value = value;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml
new file mode 100644
index 0000000..3822b31
--- /dev/null
+++ b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+
+<!DOCTYPE hibernate-configuration PUBLIC
+        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
+        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
+
+<hibernate-configuration>
+    <session-factory>
+        <!-- Show SQL. -->
+        <property name="show_sql">true</property>
+
+        <!-- Database connection settings (private in-memory database). -->
+        <property name="connection.url">jdbc:h2:mem:example;DB_CLOSE_DELAY=-1</property>
+
+        <!-- Only validate the database schema on startup in production mode. -->
+        <property name="hbm2ddl.auto">update</property>
+
+        <!-- H2 dialect. -->
+        <property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
+
+        <!-- Mappings. -->
+        <mapping resource="org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml"/>
+    </session-factory>
+</hibernate-configuration>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/package-info.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/package-info.java b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/package-info.java
new file mode 100644
index 0000000..8af9886
--- /dev/null
+++ b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * <!-- Package description. -->
+ * Contains internal tests or test related classes and interfaces.
+ */
+package org.apache.ignite.cache.store.hibernate;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/test/java/org/apache/ignite/testsuites/IgniteBinaryHibernate5TestSuite.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/test/java/org/apache/ignite/testsuites/IgniteBinaryHibernate5TestSuite.java b/modules/hibernate-5.1/src/test/java/org/apache/ignite/testsuites/IgniteBinaryHibernate5TestSuite.java
new file mode 100644
index 0000000..d539511
--- /dev/null
+++ b/modules/hibernate-5.1/src/test/java/org/apache/ignite/testsuites/IgniteBinaryHibernate5TestSuite.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.testsuites;
+
+import junit.framework.TestSuite;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.testframework.config.GridTestProperties;
+
+/**
+ *
+ */
+public class IgniteBinaryHibernate5TestSuite extends TestSuite {
+    /**
+     * @return Test suite.
+     * @throws Exception If failed.
+     */
+    public static TestSuite suite() throws Exception {
+        GridTestProperties.setProperty(GridTestProperties.MARSH_CLASS_NAME, BinaryMarshaller.class.getName());
+
+        return IgniteHibernate5TestSuite.suite();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/test/java/org/apache/ignite/testsuites/IgniteHibernate5TestSuite.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/test/java/org/apache/ignite/testsuites/IgniteHibernate5TestSuite.java b/modules/hibernate-5.1/src/test/java/org/apache/ignite/testsuites/IgniteHibernate5TestSuite.java
new file mode 100644
index 0000000..3d7c4ee
--- /dev/null
+++ b/modules/hibernate-5.1/src/test/java/org/apache/ignite/testsuites/IgniteHibernate5TestSuite.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.testsuites;
+
+import junit.framework.TestSuite;
+import org.apache.ignite.cache.hibernate.HibernateL2CacheConfigurationSelfTest;
+import org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest;
+import org.apache.ignite.cache.hibernate.HibernateL2CacheTransactionalSelfTest;
+import org.apache.ignite.cache.hibernate.HibernateL2CacheTransactionalUseSyncSelfTest;
+import org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreNodeRestartTest;
+import org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreSelfTest;
+import org.apache.ignite.cache.store.hibernate.CacheHibernateStoreFactorySelfTest;
+import org.apache.ignite.cache.store.hibernate.CacheHibernateStoreSessionListenerSelfTest;
+
+/**
+ * Hibernate integration tests.
+ */
+public class IgniteHibernate5TestSuite extends TestSuite {
+    /**
+     * @return Test suite.
+     * @throws Exception Thrown in case of the failure.
+     */
+    public static TestSuite suite() throws Exception {
+        TestSuite suite = new TestSuite("Hibernate5 Integration Test Suite");
+
+        // Hibernate L2 cache.
+        suite.addTestSuite(HibernateL2CacheSelfTest.class);
+        suite.addTestSuite(HibernateL2CacheTransactionalSelfTest.class);
+        suite.addTestSuite(HibernateL2CacheTransactionalUseSyncSelfTest.class);
+        suite.addTestSuite(HibernateL2CacheConfigurationSelfTest.class);
+
+        suite.addTestSuite(CacheHibernateBlobStoreSelfTest.class);
+
+        suite.addTestSuite(CacheHibernateBlobStoreNodeRestartTest.class);
+
+        suite.addTestSuite(CacheHibernateStoreSessionListenerSelfTest.class);
+
+        suite.addTestSuite(CacheHibernateStoreFactorySelfTest.class);
+
+        return suite;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-core/pom.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate-core/pom.xml b/modules/hibernate-core/pom.xml
new file mode 100644
index 0000000..91ec68b
--- /dev/null
+++ b/modules/hibernate-core/pom.xml
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!--
+    POM file.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.ignite</groupId>
+        <artifactId>ignite-parent</artifactId>
+        <version>1</version>
+        <relativePath>../../parent</relativePath>
+    </parent>
+
+    <artifactId>ignite-hibernate-core</artifactId>
+    <version>2.0.0-SNAPSHOT</version>
+    <url>http://ignite.apache.org</url>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-core</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-jta</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <testResources>
+            <testResource>
+                <directory>src/main/java</directory>
+                <excludes>
+                    <exclude>**/*.java</exclude>
+                </excludes>
+            </testResource>
+            <testResource>
+                <directory>src/test/java</directory>
+                <excludes>
+                    <exclude>**/*.java</exclude>
+                </excludes>
+            </testResource>
+        </testResources>
+
+        <plugins>
+            <!-- Generate the OSGi MANIFEST.MF for this bundle. -->
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+</project>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyAdapter.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyAdapter.java b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyAdapter.java
new file mode 100644
index 0000000..557b018
--- /dev/null
+++ b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyAdapter.java
@@ -0,0 +1,340 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.resources.IgniteInstanceResource;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Common interface used to implement Hibernate L2 cache access strategies.
+ * <p>
+ * The expected sequences of steps related to various CRUD operations executed by Hibernate are:
+ * <p>
+ * Insert:
+ * <ul>
+ *     <li>Start DB transaction.</li>
+ *     <li>Execute database insert.</li>
+ *     <li>Call {@link HibernateAccessStrategyAdapter#insert}.</li>
+ *     <li>Commit DB transaction.</li>
+ *     <li>Call {@link HibernateAccessStrategyAdapter#afterInsert}.</li>
+ * </ul>
+ * In case if some step fails and DB transaction is rolled back then
+ * {@link HibernateAccessStrategyAdapter#afterInsert} is not called.
+ * <p>
+ * Update:
+ * <ul>
+ *     <li>Start DB transaction.</li>
+ *     <li>Call {@link HibernateAccessStrategyAdapter#lock}.</li>
+ *     <li>Execute database update.</li>
+ *     <li>Call {@link HibernateAccessStrategyAdapter#update}.</li>
+ *     <li>Commit DB transaction.</li>
+ *     <li>Call {@link HibernateAccessStrategyAdapter#afterUpdate}.</li>
+ * </ul>
+ * In case if {@link HibernateAccessStrategyAdapter#lock} was called, but some other step fails and DB
+ * transaction is rolled back then {@link HibernateAccessStrategyAdapter#unlock} is called for all locked keys.
+ * <p>
+ * Delete:
+ * <ul>
+ *     <li>Start DB transaction.</li>
+ *     <li>Call {@link HibernateAccessStrategyAdapter#lock} for removing key.</li>
+ *     <li>Execute database delete.</li>
+ *     <li>Call {@link HibernateAccessStrategyAdapter#remove}.</li>
+ *     <li>Commit DB transaction.</li>
+ *     <li>Call {@link HibernateAccessStrategyAdapter#unlock}.</li>
+ * </ul>
+ * In case if {@link HibernateAccessStrategyAdapter#lock} was called, but some other step fails and DB
+ * transaction is rolled back then {@link HibernateAccessStrategyAdapter#unlock} is called for all locked keys.
+ * <p>
+ * In case if custom SQL update query is executed Hibernate clears entire cache region,
+ * for this case operations sequence is:
+ * <ul>
+ *     <li>Start DB transaction.</li>
+ *     <li>Call {@link HibernateAccessStrategyAdapter#lockRegion}.</li>
+ *     <li>Execute database query.</li>
+ *     <li>Call {@link HibernateAccessStrategyAdapter#removeAll}.</li>
+ *     <li>Commit DB transaction.</li>
+ *     <li>Call {@link HibernateAccessStrategyAdapter#unlockRegion}.</li>
+ * </ul>
+ */
+public abstract class HibernateAccessStrategyAdapter {
+    /** */
+    protected final HibernateCacheProxy cache;
+
+    /** */
+    private final HibernateExceptionConverter eConverter;
+
+    /** Grid. */
+    protected final Ignite ignite;
+
+    /** */
+    protected final IgniteLogger log;
+
+    /**
+     * @param ignite Node.
+     * @param cache Cache.
+     * @param eConverter Exception converter.
+     */
+    protected HibernateAccessStrategyAdapter(Ignite ignite,
+        HibernateCacheProxy cache,
+        HibernateExceptionConverter eConverter) {
+        this.cache = cache;
+        this.ignite = ignite;
+        this.eConverter = eConverter;
+
+        log = ignite.log().getLogger(getClass());
+    }
+
+    /**
+     * @param e Exception.
+     * @return Runtime exception to be thrown.
+     */
+    final RuntimeException convertException(Exception e) {
+        return eConverter.convert(e);
+    }
+
+    /**
+     * @param key Key.
+     * @return Cached value.
+     */
+    @Nullable public Object get(Object key) {
+        try {
+            return cache.get(key);
+        }
+        catch (IgniteCheckedException e) {
+            throw convertException(e);
+        }
+    }
+
+    /**
+     * @param key Key.
+     * @param val Value.
+     * @param minimalPutOverride MinimalPut flag
+     */
+    public void putFromLoad(Object key, Object val, boolean minimalPutOverride) {
+        putFromLoad(key, val);
+    }
+
+    /**
+     * Puts in cache value loaded from the database.
+     *
+     * @param key Key.
+     * @param val Value.
+     */
+    public void putFromLoad(Object key, Object val) {
+        try {
+            cache.put(key, val);
+        }
+        catch (IgniteCheckedException e) {
+            throw convertException(e);
+        }
+    }
+
+    /**
+     * Called during database transaction execution before Hibernate attempts to update or remove given key.
+     *
+     * @param key Key.
+     */
+    public abstract void lock(Object key);
+
+    /**
+     * Called after Hibernate failed to update or successfully removed given key.
+     *
+     * @param key Key.
+     */
+    public abstract void unlock(Object key);
+
+    /**
+     * Called after Hibernate updated object in the database but before transaction completed.
+     *
+     * @param key Key.
+     * @param val Value.
+     * @return {@code True} if operation updated cache.
+     */
+    public abstract boolean update(Object key, Object val);
+
+    /**
+     * Called after Hibernate updated object in the database and transaction successfully completed.
+     *
+     * @param key Key.
+     * @param val Value.
+     * @return {@code True} if operation updated cache.
+     */
+    public abstract boolean afterUpdate(Object key, Object val);
+
+    /**
+     * Called after Hibernate inserted object in the database but before transaction completed.
+     *
+     * @param key Key.
+     * @param val Value.
+     * @return {@code True} if operation updated cache.
+     */
+    public abstract boolean insert(Object key, Object val);
+
+    /**
+     * Called after Hibernate inserted object in the database and transaction successfully completed.
+     *
+     * @param key Key.
+     * @param val Value.
+     * @return {@code True} if operation updated cache.
+     */
+    public abstract boolean afterInsert(Object key, Object val);
+
+    /**
+     * Called after Hibernate removed object from database but before transaction completed.
+     *
+     * @param key Key,
+     */
+    public abstract void remove(Object key);
+
+    /**
+     * Called to remove object from cache without regard to transaction.
+     *
+     * @param key Key.
+     */
+    public void evict(Object key) {
+        evict(ignite, cache, key);
+    }
+
+    /**
+     * Called to remove all data from cache without regard to transaction.
+     */
+    public void evictAll() {
+        try {
+            evictAll(cache);
+        }
+        catch (IgniteCheckedException e) {
+            throw convertException(e);
+        }
+    }
+
+    /**
+     * Called during database transaction execution to clear entire cache region after
+     * Hibernate executed database update, but before transaction completed.
+     */
+    public final void removeAll() {
+        evictAll();
+    }
+
+    /**
+     * Called during database transaction execution before Hibernate executed
+     * update operation which should invalidate entire cache region.
+     */
+    public void lockRegion() {
+        // No-op.
+    }
+
+    /**
+     * Called after transaction clearing entire cache region completed.
+     */
+    public void unlockRegion() {
+        // No-op.
+    }
+
+    /**
+     * Called to remove object from cache without regard to transaction.
+     *
+     * @param ignite Grid.
+     * @param cache Cache.
+     * @param key Key.
+     */
+    public static void evict(Ignite ignite, HibernateCacheProxy cache, Object key) {
+        key = cache.keyTransformer().transform(key);
+
+        ignite.compute(ignite.cluster()).call(new ClearKeyCallable(key, cache.name()));
+    }
+
+    /**
+     * Called to remove all data from cache without regard to transaction.
+     *
+     * @param cache Cache.
+     * @throws IgniteCheckedException If failed.
+     */
+    public static void evictAll(IgniteInternalCache<Object, Object> cache) throws IgniteCheckedException {
+        cache.clear();
+    }
+
+    /**
+     * Callable invalidates given key.
+     */
+    private static class ClearKeyCallable implements IgniteCallable<Void>, Externalizable {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** */
+        @IgniteInstanceResource
+        private Ignite ignite;
+
+        /** */
+        private Object key;
+
+        /** */
+        private String cacheName;
+
+        /**
+         * Empty constructor required by {@link Externalizable}.
+         */
+        public ClearKeyCallable() {
+            // No-op.
+        }
+
+        /**
+         * @param key Key to clear.
+         * @param cacheName Cache name.
+         */
+        private ClearKeyCallable(Object key, String cacheName) {
+            this.key = key;
+            this.cacheName = cacheName;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Void call() throws IgniteCheckedException {
+            IgniteInternalCache<Object, Object> cache = ((IgniteKernal)ignite).getCache(cacheName);
+
+            assert cache != null;
+
+            cache.clearLocally(key);
+
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeExternal(ObjectOutput out) throws IOException {
+            out.writeObject(key);
+
+            U.writeString(out, cacheName);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+            key = in.readObject();
+
+            cacheName = U.readString(in);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyFactory.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyFactory.java b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyFactory.java
new file mode 100644
index 0000000..0226c1c
--- /dev/null
+++ b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateAccessStrategyFactory.java
@@ -0,0 +1,235 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.configuration.TransactionConfiguration;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
+import org.apache.ignite.internal.util.typedef.G;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+
+/**
+ * Access strategy factory.
+ */
+public class HibernateAccessStrategyFactory {
+    /** */
+    private final HibernateKeyTransformer keyTransformer;
+
+    /** */
+    private final HibernateExceptionConverter eConverter;
+
+    /**
+     * Hibernate L2 cache grid name property name.
+     *
+     * @deprecated Use {@link #IGNITE_INSTANCE_NAME_PROPERTY}.
+     *      If {@link #IGNITE_INSTANCE_NAME_PROPERTY} is specified it takes precedence.
+     */
+    @Deprecated
+    public static final String GRID_NAME_PROPERTY = "org.apache.ignite.hibernate.grid_name";
+
+    /** Hibernate L2 cache Ignite instance name property name. */
+    public static final String IGNITE_INSTANCE_NAME_PROPERTY = "org.apache.ignite.hibernate.ignite_instance_name";
+
+    /** Default cache property name. */
+    public static final String DFLT_CACHE_NAME_PROPERTY = "org.apache.ignite.hibernate.default_cache";
+
+    /** Property prefix used to specify region name to cache name mapping. */
+    public static final String REGION_CACHE_PROPERTY = "org.apache.ignite.hibernate.region_cache.";
+
+    /** */
+    public static final String DFLT_ACCESS_TYPE_PROPERTY = "org.apache.ignite.hibernate.default_access_type";
+
+    /** */
+    public static final String GRID_CONFIG_PROPERTY = "org.apache.ignite.hibernate.grid_config";
+
+    /** Grid providing caches. */
+    private Ignite ignite;
+
+    /** Default cache. */
+    private HibernateCacheProxy dfltCache;
+
+    /** Region name to cache name mapping. */
+    private final Map<String, String> regionCaches = new HashMap<>();
+
+    /** */
+    private final ThreadLocal threadLoc = new ThreadLocal();
+
+    /** */
+    private final ConcurrentHashMap<String, ThreadLocal> threadLocMap = new ConcurrentHashMap<>();
+
+    /**
+     * @param keyTransformer Key transformer.
+     * @param eConverter Exception converter.
+     */
+    HibernateAccessStrategyFactory(HibernateKeyTransformer keyTransformer, HibernateExceptionConverter eConverter) {
+        this.keyTransformer = keyTransformer;
+        this.eConverter = eConverter;
+    }
+
+    /**
+     * @param props Properties.
+     */
+    public void start(Properties props)  {
+        String gridCfg = props.getProperty(GRID_CONFIG_PROPERTY);
+        String igniteInstanceName = props.getProperty(IGNITE_INSTANCE_NAME_PROPERTY);
+
+        if (igniteInstanceName == null)
+            igniteInstanceName = props.getProperty(GRID_NAME_PROPERTY);
+
+        if (gridCfg != null) {
+            try {
+                ignite = G.start(gridCfg);
+            }
+            catch (IgniteException e) {
+                throw eConverter.convert(e);
+            }
+        }
+        else
+            ignite = Ignition.ignite(igniteInstanceName);
+
+        for (Map.Entry<Object, Object> prop : props.entrySet()) {
+            String key = prop.getKey().toString();
+
+            if (key.startsWith(REGION_CACHE_PROPERTY)) {
+                String regionName = key.substring(REGION_CACHE_PROPERTY.length());
+
+                String cacheName = prop.getValue().toString();
+
+                if (((IgniteKernal)ignite).getCache(cacheName) == null)
+                    throw new IllegalArgumentException("Cache '" + cacheName + "' specified for region '" + regionName + "' " +
+                        "is not configured.");
+
+                regionCaches.put(regionName, cacheName);
+            }
+        }
+
+        String dfltCacheName = props.getProperty(DFLT_CACHE_NAME_PROPERTY);
+
+        if (dfltCacheName != null) {
+            IgniteInternalCache<Object, Object> dfltCache = ((IgniteKernal)ignite).getCache(dfltCacheName);
+
+            if (dfltCache == null)
+                throw new IllegalArgumentException("Cache specified as default is not configured: " + dfltCacheName);
+
+            this.dfltCache = new HibernateCacheProxy(dfltCache, keyTransformer);
+        }
+
+        IgniteLogger log = ignite.log().getLogger(getClass());
+
+        if (log.isDebugEnabled())
+            log.debug("HibernateRegionFactory started [igniteInstanceName=" + igniteInstanceName + ']');
+    }
+
+    /**
+     * @return Ignite node.
+     */
+    public Ignite node() {
+        return ignite;
+    }
+
+    /**
+     * @param regionName L2 cache region name.
+     * @return Cache for given region.
+     */
+    HibernateCacheProxy regionCache(String regionName) {
+        String cacheName = regionCaches.get(regionName);
+
+        if (cacheName == null) {
+            if (dfltCache != null)
+                return dfltCache;
+
+            cacheName = regionName;
+        }
+
+        IgniteInternalCache<Object, Object> cache = ((IgniteKernal)ignite).getCache(cacheName);
+
+        if (cache == null)
+            throw new IllegalArgumentException("Cache '" + cacheName + "' for region '" + regionName + "' is not configured.");
+
+        return new HibernateCacheProxy(cache, keyTransformer);
+    }
+
+    /**
+     * @param cache Cache.
+     * @return Access strategy implementation.
+     */
+    HibernateAccessStrategyAdapter createReadOnlyStrategy(HibernateCacheProxy cache) {
+        return new HibernateReadOnlyAccessStrategy(ignite, cache, eConverter);
+    }
+
+    /**
+     * @param cache Cache.
+     * @return Access strategy implementation.
+     */
+    HibernateAccessStrategyAdapter createNonStrictReadWriteStrategy(HibernateCacheProxy cache) {
+        ThreadLocal threadLoc = threadLocMap.get(cache.name());
+
+        if (threadLoc == null) {
+            ThreadLocal old = threadLocMap.putIfAbsent(cache.name(), threadLoc = new ThreadLocal());
+
+            if (old != null)
+                threadLoc = old;
+        }
+
+        return new HibernateNonStrictAccessStrategy(ignite, cache, threadLoc, eConverter);
+    }
+
+    /**
+     * @param cache Cache.
+     * @return Access strategy implementation.
+     */
+    HibernateAccessStrategyAdapter createReadWriteStrategy(HibernateCacheProxy cache) {
+        if (cache.configuration().getAtomicityMode() != TRANSACTIONAL)
+            throw new IllegalArgumentException("Hibernate READ-WRITE access strategy must have Ignite cache with " +
+                "'TRANSACTIONAL' atomicity mode: " + cache.name());
+
+        return new HibernateReadWriteAccessStrategy(ignite, cache, threadLoc, eConverter);
+    }
+
+    /**
+     * @param cache Cache.
+     * @return Access strategy implementation.
+     */
+    HibernateAccessStrategyAdapter createTransactionalStrategy(HibernateCacheProxy cache) {
+        if (cache.configuration().getAtomicityMode() != TRANSACTIONAL)
+            throw new IllegalArgumentException("Hibernate TRANSACTIONAL access strategy must have Ignite cache with " +
+                "'TRANSACTIONAL' atomicity mode: " + cache.name());
+
+        TransactionConfiguration txCfg = ignite.configuration().getTransactionConfiguration();
+
+        if (txCfg == null ||
+            (txCfg.getTxManagerFactory() == null
+                && txCfg.getTxManagerLookupClassName() == null
+                && cache.configuration().getTransactionManagerLookupClassName() == null)) {
+            throw new IllegalArgumentException("Hibernate TRANSACTIONAL access strategy must have Ignite with " +
+                "Factory<TransactionManager> configured (see IgniteConfiguration." +
+                "getTransactionConfiguration().setTxManagerFactory()): " + cache.name());
+        }
+
+        return new HibernateTransactionalAccessStrategy(ignite, cache, eConverter);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateCacheProxy.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateCacheProxy.java b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateCacheProxy.java
new file mode 100644
index 0000000..3d439dd
--- /dev/null
+++ b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateCacheProxy.java
@@ -0,0 +1,801 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import javax.cache.Cache;
+import javax.cache.expiry.ExpiryPolicy;
+import javax.cache.processor.EntryProcessor;
+import javax.cache.processor.EntryProcessorResult;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.cache.CacheEntry;
+import org.apache.ignite.cache.CacheMetrics;
+import org.apache.ignite.cache.CachePeekMode;
+import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.cluster.ClusterGroup;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.CacheEntryPredicate;
+import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy;
+import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
+import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
+import org.apache.ignite.lang.IgniteBiPredicate;
+import org.apache.ignite.mxbean.CacheMetricsMXBean;
+import org.apache.ignite.transactions.Transaction;
+import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionIsolation;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Hibernate cache proxy used to substitute hibernate keys with ignite keys.
+ */
+public class HibernateCacheProxy implements IgniteInternalCache<Object, Object> {
+    /** Delegate. */
+    private final IgniteInternalCache<Object, Object> delegate;
+
+    /** Transformer. */
+    private final HibernateKeyTransformer keyTransformer;
+
+    /**
+     * @param delegate Delegate.
+     * @param keyTransformer Key keyTransformer.
+     */
+    HibernateCacheProxy(
+        IgniteInternalCache<Object, Object> delegate,
+        HibernateKeyTransformer keyTransformer
+    ) {
+        assert delegate != null;
+        assert keyTransformer != null;
+
+        this.delegate = delegate;
+        this.keyTransformer = keyTransformer;
+    }
+
+    /**
+     * @return HibernateKeyTransformer
+     */
+    public HibernateKeyTransformer keyTransformer(){
+        return keyTransformer;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String name() {
+        return delegate.name();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean skipStore() {
+        return delegate.skipStore();
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalCache setSkipStore(boolean skipStore) {
+        return delegate.setSkipStore(skipStore);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isEmpty() {
+        return delegate.isEmpty();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean containsKey(Object key) {
+        return delegate.containsKey(keyTransformer.transform(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Boolean> containsKeyAsync(Object key) {
+        return delegate.containsKeyAsync(keyTransformer.transform(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean containsKeys(Collection keys) {
+        return delegate.containsKey(transform(keys));
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Boolean> containsKeysAsync(Collection keys) {
+        return delegate.containsKeysAsync(transform(keys));
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public Object localPeek(
+        Object key,
+        CachePeekMode[] peekModes,
+        @Nullable IgniteCacheExpiryPolicy plc
+    ) throws IgniteCheckedException {
+        return delegate.localPeek(keyTransformer.transform(key), peekModes, plc);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Iterable<Cache.Entry<Object, Object>> localEntries(
+        CachePeekMode[] peekModes
+    ) throws IgniteCheckedException {
+        return delegate.localEntries(peekModes);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public Object get(Object key) throws IgniteCheckedException {
+        return delegate.get(keyTransformer.transform(key));
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public CacheEntry getEntry(Object key) throws IgniteCheckedException {
+        return delegate.getEntry(keyTransformer.transform(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture getAsync(Object key) {
+        return delegate.getAsync(keyTransformer.transform(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<CacheEntry<Object, Object>> getEntryAsync(Object key) {
+        return delegate.getEntryAsync(keyTransformer.transform(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Map getAll(@Nullable Collection keys) throws IgniteCheckedException {
+        return delegate.getAll(transform(keys));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<CacheEntry<Object, Object>> getEntries(
+        @Nullable Collection keys) throws IgniteCheckedException {
+        return delegate.getEntries(transform(keys));
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Map<Object, Object>> getAllAsync(@Nullable Collection keys) {
+        return delegate.getAllAsync(transform(keys));
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Collection<CacheEntry<Object,Object>>> getEntriesAsync(
+        @Nullable Collection keys
+    ) {
+        return delegate.getEntriesAsync(transform(keys));
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public Object getAndPut(Object key, Object val) throws IgniteCheckedException {
+        return delegate.getAndPut(keyTransformer.transform(key), val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture getAndPutAsync(Object key, Object val) {
+        return delegate.getAndPutAsync(keyTransformer.transform(key), val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean put(Object key, Object val) throws IgniteCheckedException {
+        return delegate.put(keyTransformer.transform(key), val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Boolean> putAsync(Object key, Object val) {
+        return delegate.putAsync(keyTransformer.transform(key), val);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public Object getAndPutIfAbsent(Object key, Object val) throws IgniteCheckedException {
+        return delegate.getAndPutIfAbsent(keyTransformer.transform(key), val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture getAndPutIfAbsentAsync(Object key, Object val) {
+        return delegate.getAndPutIfAbsentAsync(keyTransformer.transform(key), val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean putIfAbsent(Object key, Object val) throws IgniteCheckedException {
+        return delegate.putIfAbsent(keyTransformer.transform(key), val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Boolean> putIfAbsentAsync(Object key, Object val) {
+        return delegate.putIfAbsentAsync(keyTransformer.transform(key), val);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public Object getAndReplace(Object key, Object val) throws IgniteCheckedException {
+        return delegate.getAndReplace(keyTransformer.transform(key), val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture getAndReplaceAsync(Object key, Object val) {
+        return delegate.getAndReplaceAsync(keyTransformer.transform(key), val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean replace(Object key, Object val) throws IgniteCheckedException {
+        return delegate.replace(keyTransformer.transform(key), val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Boolean> replaceAsync(Object key, Object val) {
+        return delegate.replaceAsync(keyTransformer.transform(key), val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean replace(Object key, Object oldVal, Object newVal) throws IgniteCheckedException {
+        return delegate.replace(keyTransformer.transform(key), oldVal, newVal);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Boolean> replaceAsync(Object key, Object oldVal, Object newVal) {
+        return delegate.replaceAsync(keyTransformer.transform(key), oldVal, newVal);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void putAll(@Nullable Map m) throws IgniteCheckedException {
+        delegate.putAll(transform(m));
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<?> putAllAsync(@Nullable Map m) {
+        return delegate.putAllAsync(transform(m));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Set keySet() {
+        return delegate.keySet();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Set keySetx() {
+        return delegate.keySetx();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Set primaryKeySet() {
+        return delegate.primaryKeySet();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Iterable values() {
+        return delegate.values();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Set<Cache.Entry<Object, Object>> entrySet() {
+        return delegate.entrySet();
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public Set<Cache.Entry<Object,Object>> entrySet(int part) {
+        return delegate.entrySet(part);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Set<Cache.Entry<Object, Object>> entrySetx(CacheEntryPredicate... filter) {
+        return delegate.entrySetx(filter);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Transaction txStart(
+        TransactionConcurrency concurrency,
+        TransactionIsolation isolation
+    ) {
+        return delegate.txStart(concurrency, isolation);
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridNearTxLocal txStartEx(
+        TransactionConcurrency concurrency,
+        TransactionIsolation isolation
+    ) {
+        return delegate.txStartEx(concurrency, isolation);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Transaction txStart(
+        TransactionConcurrency concurrency,
+        TransactionIsolation isolation,
+        long timeout,
+        int txSize
+    ) {
+        return delegate.txStart(concurrency, isolation, timeout, txSize);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public GridNearTxLocal tx() {
+        return delegate.tx();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean evict(Object key) {
+        return delegate.evict(keyTransformer.transform(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void evictAll(@Nullable Collection keys) {
+        delegate.evictAll(transform(keys));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void clearLocally(boolean srv, boolean near, boolean readers) {
+        delegate.clearLocally(srv, near, readers);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean clearLocally(Object key) {
+        return delegate.clearLocally(keyTransformer.transform(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void clearLocallyAll(Set keys, boolean srv, boolean near, boolean readers) {
+        delegate.clearLocallyAll((Set<?>)transform(keys), srv, near, readers);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void clear(Object key) throws IgniteCheckedException {
+        delegate.clear(keyTransformer.transform(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void clearAll(Set keys) throws IgniteCheckedException {
+        delegate.clearAll((Set<?>)transform(keys));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void clear() throws IgniteCheckedException {
+        delegate.clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<?> clearAsync() {
+        return delegate.clearAsync();
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<?> clearAsync(Object key) {
+        return delegate.clearAsync(keyTransformer.transform(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<?> clearAllAsync(Set keys) {
+        return delegate.clearAllAsync((Set<?>)transform(keys));
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public Object getAndRemove(Object key) throws IgniteCheckedException {
+        return delegate.getAndRemove(keyTransformer.transform(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture getAndRemoveAsync(Object key) {
+        return delegate.getAndRemoveAsync(keyTransformer.transform(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean remove(Object key) throws IgniteCheckedException {
+        return delegate.remove(keyTransformer.transform(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Boolean> removeAsync(Object key) {
+        return delegate.removeAsync(keyTransformer.transform(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean remove(Object key, Object val) throws IgniteCheckedException {
+        return delegate.remove(keyTransformer.transform(key), val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Boolean> removeAsync(Object key, Object val) {
+        return delegate.removeAsync(keyTransformer.transform(key), val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void removeAll(@Nullable Collection keys) throws IgniteCheckedException {
+        delegate.removeAll(transform(keys));
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<?> removeAllAsync(@Nullable Collection keys) {
+        return delegate.removeAllAsync(transform(keys));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void removeAll() throws IgniteCheckedException {
+        delegate.removeAll();
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<?> removeAllAsync() {
+        return delegate.removeAllAsync();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean lock(Object key, long timeout) throws IgniteCheckedException {
+        return delegate.lock(keyTransformer.transform(key), timeout);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Boolean> lockAsync(Object key, long timeout) {
+        return delegate.lockAsync(keyTransformer.transform(key), timeout);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean lockAll(@Nullable Collection keys, long timeout) throws IgniteCheckedException {
+        return delegate.lockAll(transform(keys), timeout);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Boolean> lockAllAsync(@Nullable Collection keys, long timeout) {
+        return delegate.lockAllAsync(transform(keys), timeout);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unlock(Object key) throws IgniteCheckedException {
+        delegate.unlock(keyTransformer.transform(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unlockAll(@Nullable Collection keys) throws IgniteCheckedException {
+        delegate.unlockAll(transform(keys));
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isLocked(Object key) {
+        return delegate.isLocked(keyTransformer.transform(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isLockedByThread(Object key) {
+        return delegate.isLockedByThread(keyTransformer.transform(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        return delegate.size();
+    }
+
+    /** {@inheritDoc} */
+    @Override public long sizeLong() {
+        return delegate.sizeLong();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int localSize(CachePeekMode[] peekModes) throws IgniteCheckedException {
+        return delegate.localSize(peekModes);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long localSizeLong(CachePeekMode[] peekModes) throws IgniteCheckedException {
+        return delegate.localSizeLong(peekModes);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long localSizeLong(int partition, CachePeekMode[] peekModes) throws IgniteCheckedException {
+        return delegate.localSizeLong(partition, peekModes);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size(CachePeekMode[] peekModes) throws IgniteCheckedException {
+        return delegate.size(peekModes);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long sizeLong(CachePeekMode[] peekModes) throws IgniteCheckedException {
+        return delegate.sizeLong(peekModes);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long sizeLong(int partition, CachePeekMode[] peekModes) throws IgniteCheckedException {
+        return delegate.sizeLong(partition, peekModes);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Integer> sizeAsync(CachePeekMode[] peekModes) {
+        return delegate.sizeAsync(peekModes);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Long> sizeLongAsync(CachePeekMode[] peekModes) {
+        return delegate.sizeLongAsync(peekModes);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Long> sizeLongAsync(int partition, CachePeekMode[] peekModes) {
+        return delegate.sizeLongAsync(partition, peekModes);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int nearSize() {
+        return delegate.nearSize();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int primarySize() {
+        return delegate.primarySize();
+    }
+
+    /** {@inheritDoc} */
+    @Override public long primarySizeLong() {
+        return delegate.primarySizeLong();
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheConfiguration configuration() {
+        return delegate.configuration();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Affinity affinity() {
+        return delegate.affinity();
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheMetrics clusterMetrics() {
+        return delegate.clusterMetrics();
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheMetrics clusterMetrics(ClusterGroup grp) {
+        return delegate.clusterMetrics(grp);
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheMetrics localMetrics() {
+        return delegate.localMetrics();
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheMetricsMXBean clusterMxBean() {
+        return delegate.clusterMxBean();
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheMetricsMXBean localMxBean() {
+        return delegate.localMxBean();
+    }
+
+    /** {@inheritDoc} */
+    @Override public long offHeapEntriesCount() {
+        return delegate.offHeapEntriesCount();
+    }
+
+    /** {@inheritDoc} */
+    @Override public long offHeapAllocatedSize() {
+        return delegate.offHeapAllocatedSize();
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<?> rebalance() {
+        return delegate.rebalance();
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalCache forSubjectId(UUID subjId) {
+        return delegate.forSubjectId(subjId);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public Object getForcePrimary(Object key) throws IgniteCheckedException {
+        return delegate.getForcePrimary(keyTransformer.transform(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture getForcePrimaryAsync(Object key) {
+        return delegate.getForcePrimaryAsync(keyTransformer.transform(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Map getAllOutTx(Set keys) throws IgniteCheckedException {
+        return delegate.getAllOutTx((Set<?>)transform(keys));
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Map<Object, Object>> getAllOutTxAsync(Set keys) {
+        return delegate.getAllOutTxAsync((Set<?>)transform(keys));
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isIgfsDataCache() {
+        return delegate.isIgfsDataCache();
+    }
+
+    /** {@inheritDoc} */
+    @Override public long igfsDataSpaceUsed() {
+        return delegate.igfsDataSpaceUsed();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isMongoDataCache() {
+        return delegate.isMongoDataCache();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isMongoMetaCache() {
+        return delegate.isMongoMetaCache();
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public ExpiryPolicy expiry() {
+        return delegate.expiry();
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalCache withExpiryPolicy(ExpiryPolicy plc) {
+        return delegate.withExpiryPolicy(plc);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalCache withNoRetries() {
+        return delegate.withNoRetries();
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridCacheContext context() {
+        return delegate.context();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void localLoadCache(
+        @Nullable IgniteBiPredicate p,
+        @Nullable Object... args
+    ) throws IgniteCheckedException {
+        delegate.localLoadCache(p, args);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<?> localLoadCacheAsync(
+        @Nullable IgniteBiPredicate p,
+        @Nullable Object... args
+    ) {
+        return delegate.localLoadCacheAsync(p, args);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object getTopologySafe(Object key) throws IgniteCheckedException {
+        return delegate.getTopologySafe(keyTransformer.transform(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<Integer> lostPartitions() {
+        return delegate.lostPartitions();
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public EntryProcessorResult invoke(
+        @Nullable AffinityTopologyVersion topVer,
+        Object key,
+        EntryProcessor entryProcessor,
+        Object... args
+    ) throws IgniteCheckedException {
+        return delegate.invoke(topVer, key, entryProcessor, args);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Map> invokeAllAsync(Map map, Object... args) {
+        return delegate.invokeAllAsync(map, args);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Map invokeAll(Map map, Object... args) throws IgniteCheckedException {
+        return delegate.invokeAll(map, args);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Map> invokeAllAsync(Set keys, EntryProcessor entryProcessor, Object... args) {
+        return delegate.invokeAllAsync((Set<?>)transform(keys), entryProcessor, args);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Map invokeAll(Set keys, EntryProcessor entryProcessor, Object... args) throws IgniteCheckedException {
+        return delegate.invokeAll((Set<?>)transform(keys), entryProcessor, args);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<EntryProcessorResult> invokeAsync(
+        Object key,
+        EntryProcessor entryProcessor,
+        Object... args
+    ) {
+        return delegate.invokeAsync(keyTransformer.transform(key), entryProcessor, args);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public EntryProcessorResult invoke(
+        Object key,
+        EntryProcessor entryProcessor,
+        Object... args
+    ) throws IgniteCheckedException {
+        return delegate.invoke(keyTransformer.transform(key), entryProcessor, args);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Iterator<Cache.Entry<Object,Object>> scanIterator(
+        boolean keepBinary,
+        @Nullable IgniteBiPredicate p
+    ) throws IgniteCheckedException {
+        return delegate.scanIterator(keepBinary, p);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<?> removeAllConflictAsync(Map drMap) throws IgniteCheckedException {
+        return delegate.removeAllConflictAsync(drMap);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void removeAllConflict(Map drMap) throws IgniteCheckedException {
+        delegate.removeAllConflictAsync(drMap);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<?> putAllConflictAsync(Map drMap) throws IgniteCheckedException {
+        return delegate.putAllConflictAsync(drMap);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void putAllConflict(Map drMap) throws IgniteCheckedException {
+        delegate.putAllConflict(drMap);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalCache keepBinary() {
+        return delegate.keepBinary();
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalCache cache() {
+        return delegate.cache();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Iterator iterator() {
+        return delegate.iterator();
+    }
+
+    /**
+     * @param keys Keys.
+     */
+    private Collection<Object> transform(Collection<Object> keys) {
+        Collection<Object> res = new LinkedList<>();
+
+        for (Object o : keys)
+            res.add(keyTransformer.transform(o));
+
+        return res;
+    }
+
+    /**
+     * @param map Map.
+     */
+    private Map<Object, Object> transform(Map<Object, Object> map) {
+        Map<Object, Object> res = new HashMap<>();
+
+        Set<Map.Entry<Object, Object>> ents = map.entrySet();
+
+        for (Map.Entry<Object, Object> e : ents)
+            res.put(keyTransformer.transform(e.getKey()), e.getValue());
+
+        return res;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateExceptionConverter.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateExceptionConverter.java b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateExceptionConverter.java
new file mode 100644
index 0000000..110bec5
--- /dev/null
+++ b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateExceptionConverter.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+/**
+ * Converts Ignite errors into Hibernate runtime exceptions.
+ */
+public interface HibernateExceptionConverter {
+    /**
+     * @param e Exception.
+     * @return Converted exception.
+     */
+    public RuntimeException convert(Exception e);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyTransformer.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyTransformer.java b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyTransformer.java
new file mode 100644
index 0000000..97fc0e9
--- /dev/null
+++ b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyTransformer.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+/**
+ * An interface for transforming hibernate keys to Ignite keys.
+ */
+public interface HibernateKeyTransformer {
+    /**
+     * @param key Hibernate key.
+     * @return Transformed key.
+     */
+    public Object transform(Object key);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateNonStrictAccessStrategy.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateNonStrictAccessStrategy.java b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateNonStrictAccessStrategy.java
new file mode 100644
index 0000000..06c6f3d
--- /dev/null
+++ b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateNonStrictAccessStrategy.java
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.util.GridLeanSet;
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+/**
+ * Implementation of NONSTRICT_READ_WRITE cache access strategy.
+ * <p>
+ * Configuration of L2 cache and per-entity cache access strategy can be set in the
+ * Hibernate configuration file:
+ * <pre name="code" class="xml">
+ * &lt;hibernate-configuration&gt;
+ *     &lt;!-- Enable L2 cache. --&gt;
+ *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
+ *
+ *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
+ *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
+ *
+ *     &lt;!-- Specify entity. --&gt;
+ *     &lt;mapping class="com.example.Entity"/&gt;
+ *
+ *     &lt;!-- Enable L2 cache with nonstrict-read-write access strategy for entity. --&gt;
+ *     &lt;class-cache class="com.example.Entity" usage="nonstrict-read-write"/&gt;
+ * &lt;/hibernate-configuration&gt;
+ * </pre>
+ * Also cache access strategy can be set using annotations:
+ * <pre name="code" class="java">
+ * &#064;javax.persistence.Entity
+ * &#064;javax.persistence.Cacheable
+ * &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+ * public class Entity { ... }
+ * </pre>
+ */
+public class HibernateNonStrictAccessStrategy extends HibernateAccessStrategyAdapter {
+    /** */
+    private final ThreadLocal<WriteContext> writeCtx;
+
+    /**
+     * @param ignite Grid.
+     * @param cache Cache.
+     * @param writeCtx Thread local instance used to track updates done during one Hibernate transaction.
+     * @param eConverter Exception converter.
+     */
+    HibernateNonStrictAccessStrategy(Ignite ignite,
+        HibernateCacheProxy cache,
+        ThreadLocal writeCtx,
+        HibernateExceptionConverter eConverter) {
+        super(ignite, cache, eConverter);
+
+        this.writeCtx = (ThreadLocal<WriteContext>)writeCtx;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void lock(Object key) {
+        WriteContext ctx = writeCtx.get();
+
+        if (ctx == null)
+            writeCtx.set(ctx = new WriteContext());
+
+        ctx.locked(key);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unlock(Object key) {
+        try {
+            WriteContext ctx = writeCtx.get();
+
+            if (ctx != null && ctx.unlocked(key)) {
+                writeCtx.remove();
+
+                ctx.updateCache(cache);
+            }
+        }
+        catch (IgniteCheckedException e) {
+            throw convertException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean update(Object key, Object val) {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean afterUpdate(Object key, Object val) {
+        WriteContext ctx = writeCtx.get();
+
+        if (ctx != null) {
+            ctx.updated(key, val);
+
+            unlock(key);
+
+            return true;
+        }
+
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean insert(Object key, Object val) {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean afterInsert(Object key, Object val) {
+        try {
+            cache.put(key, val);
+
+            return true;
+        }
+        catch (IgniteCheckedException e) {
+            throw convertException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void remove(Object key) {
+        WriteContext ctx = writeCtx.get();
+
+        if (ctx != null)
+            ctx.removed(key);
+    }
+
+    /**
+     * Information about updates done during single database transaction.
+     */
+    @SuppressWarnings("TypeMayBeWeakened")
+    private static class WriteContext {
+        /** */
+        @GridToStringInclude
+        private Map<Object, Object> updates;
+
+        /** */
+        @GridToStringInclude
+        private Set<Object> rmvs;
+
+        /** */
+        @GridToStringInclude
+        private Set<Object> locked = new GridLeanSet<>();
+
+        /**
+         * Marks key as locked.
+         *
+         * @param key Key.
+         */
+        void locked(Object key) {
+            locked.add(key);
+        }
+
+        /**
+         * Marks key as unlocked.
+         *
+         * @param key Key.
+         * @return {@code True} if last locked key was unlocked.
+         */
+        boolean unlocked(Object key) {
+            locked.remove(key);
+
+            return locked.isEmpty();
+        }
+
+        /**
+         * Marks key as updated.
+         *
+         * @param key Key.
+         * @param val Value.
+         */
+        void updated(Object key, Object val) {
+            if (updates == null)
+                updates = new LinkedHashMap<>();
+
+            updates.put(key, val);
+        }
+
+        /**
+         * Marks key as removed.
+         *
+         * @param key Key.
+         */
+        void removed(Object key) {
+            if (rmvs == null)
+                rmvs = new GridLeanSet<>();
+
+            rmvs.add(key);
+        }
+
+        /**
+         * Updates cache.
+         *
+         * @param cache Cache.
+         * @throws IgniteCheckedException If failed.
+         */
+        void updateCache(HibernateCacheProxy cache) throws IgniteCheckedException {
+            if (!F.isEmpty(rmvs))
+                cache.removeAll(rmvs);
+
+            if (!F.isEmpty(updates))
+                cache.putAll(updates);
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(WriteContext.class, this);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadOnlyAccessStrategy.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadOnlyAccessStrategy.java b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadOnlyAccessStrategy.java
new file mode 100644
index 0000000..a0957fd
--- /dev/null
+++ b/modules/hibernate-core/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadOnlyAccessStrategy.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCheckedException;
+
+/**
+ * Implementation of READ_ONLY cache access strategy.
+ * <p>
+ * Configuration of L2 cache and per-entity cache access strategy can be set in the
+ * Hibernate configuration file:
+ * <pre name="code" class="xml">
+ * &lt;hibernate-configuration&gt;
+ *     &lt;!-- Enable L2 cache. --&gt;
+ *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
+ *
+ *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
+ *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
+ *
+ *     &lt;!-- Specify entity. --&gt;
+ *     &lt;mapping class="com.example.Entity"/&gt;
+ *
+ *     &lt;!-- Enable L2 cache with read-only access strategy for entity. --&gt;
+ *     &lt;class-cache class="com.example.Entity" usage="read-only"/&gt;
+ * &lt;/hibernate-configuration&gt;
+ * </pre>
+ * Also cache access strategy can be set using annotations:
+ * <pre name="code" class="java">
+ * &#064;javax.persistence.Entity
+ * &#064;javax.persistence.Cacheable
+ * &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
+ * public class Entity { ... }
+ * </pre>
+ *
+ */
+public class HibernateReadOnlyAccessStrategy extends HibernateAccessStrategyAdapter {
+    /**
+     * @param ignite Node.
+     * @param cache Cache.
+     * @param eConverter Exception converter.
+     */
+    public HibernateReadOnlyAccessStrategy(Ignite ignite,
+        HibernateCacheProxy cache,
+        HibernateExceptionConverter eConverter) {
+        super(ignite, cache, eConverter);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean insert(Object key, Object val) {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean afterInsert(Object key, Object val) {
+        try {
+            cache.put(key, val);
+
+            return true;
+        }
+        catch (IgniteCheckedException e) {
+            throw convertException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void lock(Object key) {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unlock(Object key) {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void remove(Object key) {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean update(Object key, Object val) {
+        throw new UnsupportedOperationException("Updates are not supported for read-only access strategy.");
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean afterUpdate(Object key, Object val) {
+        throw new UnsupportedOperationException("Updates are not supported for read-only access strategy.");
+    }
+}
\ No newline at end of file


[16/16] ignite git commit: ignite-1794 Refactored hibernate modules, switched to hibernate 5.1

Posted by sb...@apache.org.
ignite-1794 Refactored hibernate modules, switched to hibernate 5.1


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ee1b19d3
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ee1b19d3
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ee1b19d3

Branch: refs/heads/ignite-2.0
Commit: ee1b19d3f6eb8c07405ee6783379d4c2c20ad8c8
Parents: c9cd761
Author: sboikov <sb...@gridgain.com>
Authored: Wed Apr 26 14:18:01 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Wed Apr 26 14:18:14 2017 +0300

----------------------------------------------------------------------
 assembly/dependencies-fabric.xml                |    5 +-
 examples/pom-standalone-lgpl.xml                |    2 +-
 examples/pom-standalone.xml                     |    2 +-
 examples/pom.xml                                |   38 +-
 .../hibernate/HibernateL2CacheExample.java      |   12 +-
 modules/hibernate-4.2/README.txt                |   48 +
 modules/hibernate-4.2/licenses/apache-2.0.txt   |  202 ++
 modules/hibernate-4.2/pom.xml                   |  159 ++
 .../HibernateAbstractRegionAccessStrategy.java  |  102 +
 .../hibernate/HibernateCollectionRegion.java    |  100 +
 .../cache/hibernate/HibernateEntityRegion.java  |  112 +
 .../hibernate/HibernateGeneralDataRegion.java   |   76 +
 .../cache/hibernate/HibernateKeyWrapper.java    |   73 +
 .../hibernate/HibernateNaturalIdRegion.java     |  103 +
 .../hibernate/HibernateQueryResultsRegion.java  |   70 +
 .../ignite/cache/hibernate/HibernateRegion.java |   99 +
 .../cache/hibernate/HibernateRegionFactory.java |  179 ++
 .../hibernate/HibernateTimestampsRegion.java    |   39 +
 .../HibernateTransactionalDataRegion.java       |   84 +
 .../ignite/cache/hibernate/package-info.java    |   24 +
 .../hibernate/CacheHibernateBlobStore.java      |  542 +++++
 .../CacheHibernateBlobStoreEntry.hbm.xml        |   31 +
 .../hibernate/CacheHibernateBlobStoreEntry.java |   89 +
 .../CacheHibernateBlobStoreFactory.java         |  235 +++
 .../CacheHibernateStoreSessionListener.java     |  222 ++
 .../cache/store/hibernate/package-info.java     |   22 +
 .../src/test/config/factory-cache.xml           |   59 +
 .../src/test/config/factory-cache1.xml          |   61 +
 .../config/factory-incorrect-store-cache.xml    |   56 +
 .../HibernateL2CacheConfigurationSelfTest.java  |  409 ++++
 .../hibernate/HibernateL2CacheMultiJvmTest.java |  440 ++++
 .../hibernate/HibernateL2CacheSelfTest.java     | 1954 +++++++++++++++++
 .../HibernateL2CacheTransactionalSelfTest.java  |  154 ++
 ...nateL2CacheTransactionalUseSyncSelfTest.java |   31 +
 .../CacheHibernateBlobStoreNodeRestartTest.java |   46 +
 .../CacheHibernateBlobStoreSelfTest.java        |  113 +
 .../CacheHibernateStoreFactorySelfTest.java     |  288 +++
 ...heHibernateStoreSessionListenerSelfTest.java |  238 +++
 .../cache/store/hibernate/hibernate.cfg.xml     |   42 +
 .../cache/store/hibernate/package-info.java     |   22 +
 .../IgniteBinaryHibernateTestSuite.java         |   37 +
 .../testsuites/IgniteHibernateTestSuite.java    |   57 +
 modules/hibernate-5.1/README.txt                |   48 +
 modules/hibernate-5.1/licenses/apache-2.0.txt   |  202 ++
 modules/hibernate-5.1/pom.xml                   |  159 ++
 .../HibernateAbstractRegionAccessStrategy.java  |  103 +
 .../hibernate/HibernateCollectionRegion.java    |  114 +
 .../cache/hibernate/HibernateEntityRegion.java  |  128 ++
 .../hibernate/HibernateGeneralDataRegion.java   |   79 +
 .../cache/hibernate/HibernateKeyWrapper.java    |  109 +
 .../hibernate/HibernateNaturalIdRegion.java     |  113 +
 .../hibernate/HibernateQueryResultsRegion.java  |   70 +
 .../ignite/cache/hibernate/HibernateRegion.java |   99 +
 .../cache/hibernate/HibernateRegionFactory.java |  168 ++
 .../hibernate/HibernateTimestampsRegion.java    |   39 +
 .../HibernateTransactionalDataRegion.java       |   84 +
 .../ignite/cache/hibernate/package-info.java    |   24 +
 .../hibernate/CacheHibernateBlobStore.java      |  543 +++++
 .../CacheHibernateBlobStoreEntry.hbm.xml        |   31 +
 .../hibernate/CacheHibernateBlobStoreEntry.java |   89 +
 .../CacheHibernateBlobStoreFactory.java         |  235 +++
 .../CacheHibernateStoreSessionListener.java     |  224 ++
 .../cache/store/hibernate/package-info.java     |   22 +
 .../src/test/config/factory-cache.xml           |   59 +
 .../src/test/config/factory-cache1.xml          |   61 +
 .../config/factory-incorrect-store-cache.xml    |   56 +
 .../HibernateL2CacheConfigurationSelfTest.java  |  407 ++++
 .../hibernate/HibernateL2CacheMultiJvmTest.java |  429 ++++
 .../hibernate/HibernateL2CacheSelfTest.java     | 1960 ++++++++++++++++++
 .../HibernateL2CacheTransactionalSelfTest.java  |  154 ++
 ...nateL2CacheTransactionalUseSyncSelfTest.java |   31 +
 .../CacheHibernateBlobStoreNodeRestartTest.java |   46 +
 .../CacheHibernateBlobStoreSelfTest.java        |  114 +
 .../CacheHibernateStoreFactorySelfTest.java     |  256 +++
 ...heHibernateStoreSessionListenerSelfTest.java |  242 +++
 .../cache/store/hibernate/hibernate.cfg.xml     |   42 +
 .../cache/store/hibernate/package-info.java     |   22 +
 .../IgniteBinaryHibernate5TestSuite.java        |   37 +
 .../testsuites/IgniteHibernate5TestSuite.java   |   57 +
 modules/hibernate-core/pom.xml                  |   76 +
 .../HibernateAccessStrategyAdapter.java         |  340 +++
 .../HibernateAccessStrategyFactory.java         |  235 +++
 .../cache/hibernate/HibernateCacheProxy.java    |  801 +++++++
 .../hibernate/HibernateExceptionConverter.java  |   29 +
 .../hibernate/HibernateKeyTransformer.java      |   29 +
 .../HibernateNonStrictAccessStrategy.java       |  230 ++
 .../HibernateReadOnlyAccessStrategy.java        |  105 +
 .../HibernateReadWriteAccessStrategy.java       |  326 +++
 .../HibernateTransactionalAccessStrategy.java   |  141 ++
 .../ignite/cache/hibernate/package-info.java    |   24 +
 modules/hibernate/README.txt                    |   48 -
 modules/hibernate/licenses/apache-2.0.txt       |  202 --
 modules/hibernate/pom.xml                       |  146 --
 .../HibernateAbstractRegionAccessStrategy.java  |   98 -
 .../HibernateAccessStrategyAdapter.java         |  379 ----
 .../cache/hibernate/HibernateCacheProxy.java    |  801 -------
 .../hibernate/HibernateCollectionRegion.java    |  100 -
 .../cache/hibernate/HibernateEntityRegion.java  |  112 -
 .../hibernate/HibernateGeneralDataRegion.java   |   71 -
 .../hibernate/HibernateKeyTransformer.java      |   28 -
 .../cache/hibernate/HibernateKeyWrapper.java    |   72 -
 .../hibernate/HibernateNaturalIdRegion.java     |  100 -
 .../HibernateNonStrictAccessStrategy.java       |  222 --
 .../hibernate/HibernateQueryResultsRegion.java  |   70 -
 .../HibernateReadOnlyAccessStrategy.java        |  107 -
 .../HibernateReadWriteAccessStrategy.java       |  328 ---
 .../ignite/cache/hibernate/HibernateRegion.java |   99 -
 .../cache/hibernate/HibernateRegionFactory.java |  266 ---
 .../hibernate/HibernateTimestampsRegion.java    |   39 -
 .../HibernateTransactionalAccessStrategy.java   |  141 --
 .../HibernateTransactionalDataRegion.java       |  107 -
 .../ignite/cache/hibernate/package-info.java    |   24 -
 .../hibernate/CacheHibernateBlobStore.java      |  542 -----
 .../CacheHibernateBlobStoreEntry.hbm.xml        |   31 -
 .../hibernate/CacheHibernateBlobStoreEntry.java |   89 -
 .../CacheHibernateBlobStoreFactory.java         |  235 ---
 .../CacheHibernateStoreSessionListener.java     |  222 --
 .../cache/store/hibernate/package-info.java     |   22 -
 .../hibernate/src/test/config/factory-cache.xml |   59 -
 .../src/test/config/factory-cache1.xml          |   61 -
 .../config/factory-incorrect-store-cache.xml    |   56 -
 .../HibernateL2CacheConfigurationSelfTest.java  |  408 ----
 .../hibernate/HibernateL2CacheSelfTest.java     | 1949 -----------------
 .../HibernateL2CacheTransactionalSelfTest.java  |  154 --
 ...nateL2CacheTransactionalUseSyncSelfTest.java |   31 -
 .../CacheHibernateBlobStoreNodeRestartTest.java |   46 -
 .../CacheHibernateBlobStoreSelfTest.java        |  113 -
 .../CacheHibernateStoreFactorySelfTest.java     |  285 ---
 ...heHibernateStoreSessionListenerSelfTest.java |  238 ---
 .../cache/store/hibernate/hibernate.cfg.xml     |   42 -
 .../cache/store/hibernate/package-info.java     |   22 -
 .../IgniteBinaryHibernateTestSuite.java         |   37 -
 .../testsuites/IgniteHibernateTestSuite.java    |   57 -
 modules/hibernate5/README.txt                   |   48 -
 modules/hibernate5/licenses/apache-2.0.txt      |  202 --
 modules/hibernate5/pom.xml                      |  146 --
 .../HibernateAbstractRegionAccessStrategy.java  |   99 -
 .../HibernateAccessStrategyAdapter.java         |  379 ----
 .../cache/hibernate/HibernateCacheProxy.java    |  801 -------
 .../hibernate/HibernateCollectionRegion.java    |  114 -
 .../cache/hibernate/HibernateEntityRegion.java  |  129 --
 .../hibernate/HibernateGeneralDataRegion.java   |   72 -
 .../hibernate/HibernateKeyTransformer.java      |   28 -
 .../cache/hibernate/HibernateKeyWrapper.java    |  108 -
 .../hibernate/HibernateNaturalIdRegion.java     |  113 -
 .../HibernateNonStrictAccessStrategy.java       |  222 --
 .../hibernate/HibernateQueryResultsRegion.java  |   70 -
 .../HibernateReadOnlyAccessStrategy.java        |  107 -
 .../HibernateReadWriteAccessStrategy.java       |  328 ---
 .../ignite/cache/hibernate/HibernateRegion.java |   99 -
 .../cache/hibernate/HibernateRegionFactory.java |  255 ---
 .../hibernate/HibernateTimestampsRegion.java    |   39 -
 .../HibernateTransactionalAccessStrategy.java   |  141 --
 .../HibernateTransactionalDataRegion.java       |  107 -
 .../ignite/cache/hibernate/package-info.java    |   24 -
 .../hibernate/CacheHibernateBlobStore.java      |  542 -----
 .../CacheHibernateBlobStoreEntry.hbm.xml        |   31 -
 .../hibernate/CacheHibernateBlobStoreEntry.java |   89 -
 .../CacheHibernateBlobStoreFactory.java         |  235 ---
 .../CacheHibernateStoreSessionListener.java     |  223 --
 .../cache/store/hibernate/package-info.java     |   22 -
 .../src/test/config/factory-cache.xml           |   59 -
 .../src/test/config/factory-cache1.xml          |   61 -
 .../config/factory-incorrect-store-cache.xml    |   56 -
 .../HibernateL2CacheConfigurationSelfTest.java  |  409 ----
 .../hibernate/HibernateL2CacheSelfTest.java     | 1948 -----------------
 .../HibernateL2CacheTransactionalSelfTest.java  |  154 --
 ...nateL2CacheTransactionalUseSyncSelfTest.java |   31 -
 .../CacheHibernateBlobStoreNodeRestartTest.java |   46 -
 .../CacheHibernateBlobStoreSelfTest.java        |  113 -
 .../CacheHibernateStoreFactorySelfTest.java     |  326 ---
 ...heHibernateStoreSessionListenerSelfTest.java |  241 ---
 .../cache/store/hibernate/hibernate.cfg.xml     |   42 -
 .../cache/store/hibernate/package-info.java     |   22 -
 .../IgniteBinaryHibernate5TestSuite.java        |   37 -
 .../testsuites/IgniteHibernate5TestSuite.java   |   57 -
 .../osgi-karaf/src/main/resources/features.xml  |    2 +-
 pom.xml                                         |    9 +-
 178 files changed, 15647 insertions(+), 16667 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/assembly/dependencies-fabric.xml
----------------------------------------------------------------------
diff --git a/assembly/dependencies-fabric.xml b/assembly/dependencies-fabric.xml
index 23a1731..be68d0a 100644
--- a/assembly/dependencies-fabric.xml
+++ b/assembly/dependencies-fabric.xml
@@ -127,8 +127,9 @@
                 <exclude>org.apache.ignite:ignite-hadoop</exclude>
                 <exclude>org.apache.ignite:ignite-codegen</exclude>
                 <exclude>org.apache.ignite:ignite-apache-license-gen</exclude>
-                <exclude>org.apache.ignite:ignite-hibernate</exclude>
-                <exclude>org.apache.ignite:ignite-hibernate5</exclude>
+                <exclude>org.apache.ignite:ignite-hibernate-core</exclude>
+                <exclude>org.apache.ignite:ignite-hibernate_4.2</exclude>
+                <exclude>org.apache.ignite:ignite-hibernate_5.1</exclude>
                 <exclude>org.apache.ignite:ignite-schedule</exclude>
                 <exclude>org.apache.ignite:ignite-geospatial</exclude>
                 <exclude>org.apache.ignite:ignite-appserver-test</exclude>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/examples/pom-standalone-lgpl.xml
----------------------------------------------------------------------
diff --git a/examples/pom-standalone-lgpl.xml b/examples/pom-standalone-lgpl.xml
index 5fbb4ea..4798d03 100644
--- a/examples/pom-standalone-lgpl.xml
+++ b/examples/pom-standalone-lgpl.xml
@@ -191,7 +191,7 @@
             <dependencies>
                 <dependency>
                     <groupId>org.apache.ignite</groupId>
-                    <artifactId>ignite-hibernate</artifactId>
+                    <artifactId>ignite-hibernate_5.1</artifactId>
                     <version>to_be_replaced_by_ignite_version</version>
                 </dependency>
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/examples/pom-standalone.xml
----------------------------------------------------------------------
diff --git a/examples/pom-standalone.xml b/examples/pom-standalone.xml
index 0183563..e74082c 100644
--- a/examples/pom-standalone.xml
+++ b/examples/pom-standalone.xml
@@ -192,7 +192,7 @@
             <dependencies>
                 <dependency>
                     <groupId>org.apache.ignite</groupId>
-                    <artifactId>ignite-hibernate</artifactId>
+                    <artifactId>ignite-hibernate_5.1</artifactId>
                     <version>to_be_replaced_by_ignite_version</version>
                 </dependency>
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index 895519b..26f653d 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -64,24 +64,6 @@
 
         <dependency>
             <groupId>org.apache.ignite</groupId>
-            <artifactId>ignite-hibernate</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.ignite</groupId>
-            <artifactId>ignite-schedule</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.ignite</groupId>
-            <artifactId>ignite-geospatial</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.ignite</groupId>
             <artifactId>ignite-spring-data</artifactId>
             <version>${project.version}</version>
         </dependency>
@@ -288,6 +270,26 @@
                 <lgpl.folder>src/main/java-lgpl</lgpl.folder>
                 <lgpl.test.folder>src/test/java-lgpl</lgpl.test.folder>
             </properties>
+
+            <dependencies>
+                <dependency>
+                    <groupId>org.apache.ignite</groupId>
+                    <artifactId>ignite-hibernate_5.1</artifactId>
+                    <version>${project.version}</version>
+                </dependency>
+
+                <dependency>
+                    <groupId>org.apache.ignite</groupId>
+                    <artifactId>ignite-schedule</artifactId>
+                    <version>${project.version}</version>
+                </dependency>
+
+                <dependency>
+                    <groupId>org.apache.ignite</groupId>
+                    <artifactId>ignite-geospatial</artifactId>
+                    <version>${project.version}</version>
+                </dependency>
+            </dependencies>
         </profile>
     </profiles>
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/hibernate/HibernateL2CacheExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/hibernate/HibernateL2CacheExample.java b/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/hibernate/HibernateL2CacheExample.java
index a31d394..28aa6ca 100644
--- a/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/hibernate/HibernateL2CacheExample.java
+++ b/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/hibernate/HibernateL2CacheExample.java
@@ -31,9 +31,9 @@ import org.apache.ignite.examples.ExamplesUtils;
 import org.hibernate.Session;
 import org.hibernate.SessionFactory;
 import org.hibernate.Transaction;
+import org.hibernate.boot.MetadataSources;
+import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
 import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.service.ServiceRegistryBuilder;
 import org.hibernate.stat.SecondLevelCacheStatistics;
 
 import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
@@ -226,14 +226,14 @@ public class HibernateL2CacheExample {
      * @return New Hibernate {@link SessionFactory}.
      */
     private static SessionFactory createHibernateSessionFactory(URL hibernateCfg) {
-        ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
+        StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
 
         builder.applySetting("hibernate.connection.url", JDBC_URL);
         builder.applySetting("hibernate.show_sql", true);
 
-        return new Configuration()
-            .configure(hibernateCfg)
-            .buildSessionFactory(builder.buildServiceRegistry());
+        builder.configure(hibernateCfg);
+
+        return new MetadataSources(builder.build()).buildMetadata().buildSessionFactory();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/README.txt
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/README.txt b/modules/hibernate-4.2/README.txt
new file mode 100644
index 0000000..096b9d7
--- /dev/null
+++ b/modules/hibernate-4.2/README.txt
@@ -0,0 +1,48 @@
+Apache Ignite Hibernate Module
+------------------------------
+
+Apache Ignite Hibernate module provides Hibernate second-level cache (L2 cache) implementation based
+on Apache Ignite In-Memory Data Grid.
+
+To enable Hibernate module when starting a standalone node, move 'optional/ignite-hibernate' folder to
+'libs' folder before running 'ignite.{sh|bat}' script. The content of the module folder will
+be added to classpath in this case.
+
+Importing Hibernate Module In Maven Project
+-------------------------------------------
+
+If you are using Maven to manage dependencies of your project, you can add Hibernate module
+dependency like this (replace '${ignite.version}' with actual Ignite version you are
+interested in):
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+                        http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    ...
+    <dependencies>
+        ...
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-hibernate_4.2</artifactId>
+            <version>${ignite.version}</version>
+        </dependency>
+        ...
+    </dependencies>
+    ...
+</project>
+
+
+LGPL dependencies
+-----------------
+
+Ignite includes the following optional LGPL dependencies:
+ - Hibernate L2 Cache Integration, http://hibernate.org/orm/
+ - JTS Topology Suite for Geospatial indexing, http://tsusiatsoftware.net/jts/main.html
+ - cron4j for cron-based task scheduling, http://www.sauronsoftware.it/projects/cron4j
+
+Apache binary releases cannot include LGPL dependencies. If you would like include
+optional LGPL dependencies into your release, you should download the source release
+from Ignite website and do the build with the following maven command:
+
+mvn clean package -DskipTests -Prelease,lgpl

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/licenses/apache-2.0.txt
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/licenses/apache-2.0.txt b/modules/hibernate-4.2/licenses/apache-2.0.txt
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/modules/hibernate-4.2/licenses/apache-2.0.txt
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/pom.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/pom.xml b/modules/hibernate-4.2/pom.xml
new file mode 100644
index 0000000..c597b21
--- /dev/null
+++ b/modules/hibernate-4.2/pom.xml
@@ -0,0 +1,159 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!--
+    POM file.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.ignite</groupId>
+        <artifactId>ignite-parent</artifactId>
+        <version>1</version>
+        <relativePath>../../parent</relativePath>
+    </parent>
+
+    <artifactId>ignite-hibernate_4.2</artifactId>
+    <version>2.0.0-SNAPSHOT</version>
+    <url>http://ignite.apache.org</url>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-core</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-hibernate-core</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.hibernate</groupId>
+            <artifactId>hibernate-core</artifactId>
+            <version>4.2.21.Final</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-jta</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.ow2.jotm</groupId>
+            <artifactId>jotm-core</artifactId>
+            <version>2.1.9</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>commons-dbcp</groupId>
+            <artifactId>commons-dbcp</artifactId>
+            <version>1.4</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.h2database</groupId>
+            <artifactId>h2</artifactId>
+            <version>${h2.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>javax.resource</groupId>
+            <artifactId>connector-api</artifactId>
+            <version>1.5</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-core</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-spring</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-log4j</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-beans</artifactId>
+            <version>${spring.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context</artifactId>
+            <version>${spring.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.thoughtworks.xstream</groupId>
+            <artifactId>xstream</artifactId>
+            <version>1.4.8</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <testResources>
+            <testResource>
+                <directory>src/main/java</directory>
+                <excludes>
+                    <exclude>**/*.java</exclude>
+                </excludes>
+            </testResource>
+            <testResource>
+                <directory>src/test/java</directory>
+                <excludes>
+                    <exclude>**/*.java</exclude>
+                </excludes>
+            </testResource>
+        </testResources>
+
+        <plugins>
+            <!-- Generate the OSGi MANIFEST.MF for this bundle. -->
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+</project>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateAbstractRegionAccessStrategy.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateAbstractRegionAccessStrategy.java b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateAbstractRegionAccessStrategy.java
new file mode 100644
index 0000000..8bf4e9b
--- /dev/null
+++ b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateAbstractRegionAccessStrategy.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.spi.access.RegionAccessStrategy;
+import org.hibernate.cache.spi.access.SoftLock;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Implementation of L2 cache access strategy delegating to {@link HibernateAccessStrategyAdapter}.
+ */
+public abstract class HibernateAbstractRegionAccessStrategy implements RegionAccessStrategy {
+    /** */
+    final HibernateAccessStrategyAdapter stgy;
+
+    /**
+     * @param stgy Access strategy implementation.
+     */
+    HibernateAbstractRegionAccessStrategy(HibernateAccessStrategyAdapter stgy) {
+        this.stgy = stgy;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public Object get(Object key, long txTs) throws CacheException {
+        return stgy.get(key);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean putFromLoad(Object key, Object val, long txTs, Object ver) throws CacheException {
+        stgy.putFromLoad(key, val);
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean putFromLoad(Object key, Object val, long txTs, Object ver, boolean minimalPutOverride)
+        throws CacheException {
+        stgy.putFromLoad(key, val, minimalPutOverride);
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public SoftLock lockItem(Object key, Object ver) throws CacheException {
+        stgy.lock(key);
+
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public SoftLock lockRegion() throws CacheException {
+        stgy.lockRegion();
+
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unlockRegion(SoftLock lock) throws CacheException {
+        stgy.unlockRegion();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unlockItem(Object key, SoftLock lock) throws CacheException {
+        stgy.unlock(key);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void remove(Object key) throws CacheException {
+        stgy.remove(key);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void removeAll() throws CacheException {
+        stgy.removeAll();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void evict(Object key) throws CacheException {
+        stgy.evict(key);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void evictAll() throws CacheException {
+        stgy.evictAll();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java
new file mode 100644
index 0000000..dae476c
--- /dev/null
+++ b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateCollectionRegion.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import org.apache.ignite.Ignite;
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.spi.CacheDataDescription;
+import org.hibernate.cache.spi.CollectionRegion;
+import org.hibernate.cache.spi.access.AccessType;
+import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
+
+/**
+ * Implementation of {@link CollectionRegion}. This region is used to store collection data.
+ * <p>
+ * L2 cache for collection can be enabled in the Hibernate configuration file:
+ * <pre name="code" class="xml">
+ * &lt;hibernate-configuration&gt;
+ *     &lt;!-- Enable L2 cache. --&gt;
+ *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
+ *
+ *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
+ *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
+ *
+ *     &lt;!-- Specify entities. --&gt;
+ *     &lt;mapping class="com.example.Entity"/&gt;
+ *     &lt;mapping class="com.example.ChildEntity"/&gt;
+ *
+ *     &lt;!-- Enable L2 cache with nonstrict-read-write access strategy for entities and collection. --&gt;
+ *     &lt;collection-cache collection="com.example.Entity" usage="nonstrict-read-write"/&gt;
+ *     &lt;collection-cache collection="com.example.ChildEntity" usage="nonstrict-read-write"/&gt;
+ *     &lt;collection-cache collection="com.example.Entity.children" usage="nonstrict-read-write"/&gt;
+ * &lt;/hibernate-configuration&gt;
+ * </pre>
+ * Also cache for collection can be enabled using annotations:
+ * <pre name="code" class="java">
+ * &#064;javax.persistence.Entity
+ * public class Entity {
+ *    ...
+ *
+ *    &#064;javax.persistence.OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
+ *    &#064;javax.persistence.JoinColumn(name="PARENT_ID")
+ *    &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+ *    public List&lt;ChildEntity&gt; getChildren() {...}
+ * }
+ * </pre>
+ * Note: the collection cache does not cache the state of the actual entities in the cache, it caches only identifier
+ * values. For this reason, the collection cache should always be used in conjunction with
+ * the second-level cache for those entities expected to be cached as part of a collection cache.
+ */
+public class HibernateCollectionRegion extends HibernateTransactionalDataRegion implements CollectionRegion {
+    /**
+     * @param factory Region factory.
+     * @param name Region name.
+     * @param ignite Grid.
+     * @param cache Region cache.
+     * @param dataDesc Region data description.
+     */
+    HibernateCollectionRegion(HibernateRegionFactory factory, String name,
+        Ignite ignite, HibernateCacheProxy cache, CacheDataDescription dataDesc) {
+        super(factory, name, ignite, cache, dataDesc);
+    }
+
+    /** {@inheritDoc} */
+    @Override public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
+        return new AccessStrategy(createAccessStrategy(accessType));
+    }
+
+    /**
+     * Collection region access strategy.
+     */
+    private class AccessStrategy extends HibernateAbstractRegionAccessStrategy
+        implements CollectionRegionAccessStrategy {
+        /**
+         * @param stgy Access strategy implementation.
+         */
+        private AccessStrategy(HibernateAccessStrategyAdapter stgy) {
+            super(stgy);
+        }
+
+        /** {@inheritDoc} */
+        @Override public CollectionRegion getRegion() {
+            return HibernateCollectionRegion.this;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java
new file mode 100644
index 0000000..db921dc
--- /dev/null
+++ b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import org.apache.ignite.Ignite;
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.spi.CacheDataDescription;
+import org.hibernate.cache.spi.EntityRegion;
+import org.hibernate.cache.spi.access.AccessType;
+import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
+import org.hibernate.cache.spi.access.SoftLock;
+
+/**
+ * Implementation of {@link EntityRegion}. This region is used to store entity data.
+ * <p>
+ * L2 cache for entity can be enabled in the Hibernate configuration file:
+ * <pre name="code" class="xml">
+ * &lt;hibernate-configuration&gt;
+ *     &lt;!-- Enable L2 cache. --&gt;
+ *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
+ *
+ *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
+ *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
+ *
+ *     &lt;!-- Specify entity. --&gt;
+ *     &lt;mapping class="com.example.Entity"/&gt;
+ *
+ *     &lt;!-- Enable L2 cache with nonstrict-read-write access strategy for entity. --&gt;
+ *     &lt;class-cache class="com.example.Entity" usage="nonstrict-read-write"/&gt;
+ * &lt;/hibernate-configuration&gt;
+ * </pre>
+ * Also cache for entity can be enabled using annotations:
+ * <pre name="code" class="java">
+ * &#064;javax.persistence.Entity
+ * &#064;javax.persistence.Cacheable
+ * &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+ * public class Entity { ... }
+ * </pre>
+ */
+public class HibernateEntityRegion extends HibernateTransactionalDataRegion implements EntityRegion {
+    /**
+     * @param factory Region factory.
+     * @param name Region name.
+     * @param ignite Grid.
+     * @param cache Region cache,
+     * @param dataDesc Region data description.
+     */
+    HibernateEntityRegion(HibernateRegionFactory factory, String name, Ignite ignite,
+        HibernateCacheProxy cache, CacheDataDescription dataDesc) {
+        super(factory, name, ignite, cache, dataDesc);
+    }
+
+    /** {@inheritDoc} */
+    @Override public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
+        return new AccessStrategy(createAccessStrategy(accessType));
+    }
+
+    /**
+     * Entity region access strategy.
+     */
+    private class AccessStrategy extends HibernateAbstractRegionAccessStrategy
+        implements EntityRegionAccessStrategy {
+        /**
+         * @param stgy Access strategy implementation.
+         */
+        private AccessStrategy(HibernateAccessStrategyAdapter stgy) {
+            super(stgy);
+        }
+
+        /** {@inheritDoc} */
+        @Override public EntityRegion getRegion() {
+            return HibernateEntityRegion.this;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean insert(Object key, Object val, Object ver) throws CacheException {
+            return stgy.insert(key, val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean afterInsert(Object key, Object val, Object ver) throws CacheException {
+            return stgy.afterInsert(key, val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean update(Object key, Object val, Object currVer, Object previousVer)
+            throws CacheException {
+            return stgy.update(key, val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean afterUpdate(Object key, Object val, Object currVer, Object previousVer, SoftLock lock)
+            throws CacheException {
+            return stgy.afterUpdate(key, val);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateGeneralDataRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateGeneralDataRegion.java b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateGeneralDataRegion.java
new file mode 100644
index 0000000..578d88b
--- /dev/null
+++ b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateGeneralDataRegion.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCheckedException;
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.spi.GeneralDataRegion;
+import org.hibernate.cache.spi.QueryResultsRegion;
+import org.hibernate.cache.spi.TimestampsRegion;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Implementation of {@link GeneralDataRegion}. This interface defines common contract for {@link QueryResultsRegion}
+ * and {@link TimestampsRegion}.
+ */
+public class HibernateGeneralDataRegion extends HibernateRegion implements GeneralDataRegion {
+    /**
+     * @param factory Region factory.
+     * @param name Region name.
+     * @param ignite Grid.
+     * @param cache Region cache.
+     */
+    HibernateGeneralDataRegion(HibernateRegionFactory factory, String name,
+        Ignite ignite, HibernateCacheProxy cache) {
+        super(factory, name, ignite, cache);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public Object get(Object key) throws CacheException {
+        try {
+            return cache.get(key);
+        } catch (IgniteCheckedException e) {
+            throw new CacheException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void put(Object key, Object val) throws CacheException {
+        try {
+            cache.put(key, val);
+        } catch (IgniteCheckedException e) {
+            throw new CacheException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void evict(Object key) throws CacheException {
+        HibernateAccessStrategyAdapter.evict(ignite, cache, key);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void evictAll() throws CacheException {
+        try {
+            HibernateAccessStrategyAdapter.evictAll(cache);
+        }
+        catch (IgniteCheckedException e) {
+            throw HibernateRegionFactory.EXCEPTION_CONVERTER.convert(e);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
new file mode 100644
index 0000000..64de395
--- /dev/null
+++ b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import java.io.Serializable;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+/**
+ * Hibernate cache key wrapper.
+ */
+public class HibernateKeyWrapper implements Serializable {
+    /** Key. */
+    private final Object key;
+
+    /** Entry. */
+    private final String entry;
+
+    /** */
+    private final String tenantId;
+
+    /**
+     * @param key Key.
+     * @param entry Entry.
+     * @param tenantId Tenant ID.
+     */
+    HibernateKeyWrapper(Object key, String entry, String tenantId) {
+        this.key = key;
+        this.entry = entry;
+        this.tenantId = tenantId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o) return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        HibernateKeyWrapper that = (HibernateKeyWrapper) o;
+
+        return (key != null ? key.equals(that.key) : that.key == null) &&
+            (entry != null ? entry.equals(that.entry) : that.entry == null) &&
+            (tenantId != null ? tenantId.equals(that.tenantId) : that.tenantId == null);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = key != null ? key.hashCode() : 0;
+        res = 31 * res + (entry != null ? entry.hashCode() : 0);
+        res = 31 * res + (tenantId != null ? tenantId.hashCode() : 0);
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(HibernateKeyWrapper.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateNaturalIdRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateNaturalIdRegion.java b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateNaturalIdRegion.java
new file mode 100644
index 0000000..ae1099d
--- /dev/null
+++ b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateNaturalIdRegion.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import org.apache.ignite.Ignite;
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.spi.CacheDataDescription;
+import org.hibernate.cache.spi.NaturalIdRegion;
+import org.hibernate.cache.spi.access.AccessType;
+import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy;
+import org.hibernate.cache.spi.access.SoftLock;
+
+/**
+ * Implementation of {@link NaturalIdRegion}. This region is used to store naturalId data.
+ * <p>
+ * L2 cache for entity naturalId and target cache region can be set using annotations:
+ * <pre name="code" class="java">
+ * &#064;javax.persistence.Entity
+ * &#064;javax.persistence.Cacheable
+ * &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+ * &#064;org.hibernate.annotations.NaturalIdCache
+ * public class Entity {
+ *     &#064;org.hibernate.annotations.NaturalId
+ *     private String entityCode;
+ *
+ *     ...
+ * }
+ * </pre>
+ */
+public class HibernateNaturalIdRegion extends HibernateTransactionalDataRegion implements NaturalIdRegion {
+    /**
+     * @param factory Region factory.
+     * @param name Region name.
+     * @param ignite Grid.
+     * @param cache Region cache,
+     * @param dataDesc Region data description.
+     */
+    HibernateNaturalIdRegion(HibernateRegionFactory factory,
+        String name,
+        Ignite ignite,
+        HibernateCacheProxy cache,
+        CacheDataDescription dataDesc) {
+        super(factory, name, ignite, cache, dataDesc);
+    }
+
+    /** {@inheritDoc} */
+    @Override public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
+        return new AccessStrategy(createAccessStrategy(accessType));
+    }
+
+    /**
+     * NaturalId region access strategy.
+     */
+    private class AccessStrategy extends HibernateAbstractRegionAccessStrategy implements
+        NaturalIdRegionAccessStrategy {
+        /**
+         * @param stgy Access strategy implementation.
+         */
+        private AccessStrategy(HibernateAccessStrategyAdapter stgy) {
+            super(stgy);
+        }
+
+        /** {@inheritDoc} */
+        @Override public NaturalIdRegion getRegion() {
+            return HibernateNaturalIdRegion.this;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean insert(Object key, Object val) throws CacheException {
+            return stgy.insert(key, val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean afterInsert(Object key, Object val) throws CacheException {
+            return stgy.afterInsert(key, val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean update(Object key, Object val) throws CacheException {
+            return stgy.update(key, val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean afterUpdate(Object key, Object val, SoftLock lock) throws CacheException {
+            return stgy.afterUpdate(key, val);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateQueryResultsRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateQueryResultsRegion.java b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateQueryResultsRegion.java
new file mode 100644
index 0000000..fccbb5e
--- /dev/null
+++ b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateQueryResultsRegion.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import org.apache.ignite.Ignite;
+import org.hibernate.Query;
+import org.hibernate.cache.spi.QueryResultsRegion;
+
+/**
+ * Implementation of {@link QueryResultsRegion}. This region is used to store query results.
+ * <p>
+ * Query results caching can be enabled in the Hibernate configuration file:
+ * <pre name="code" class="xml">
+ * &lt;hibernate-configuration&gt;
+ *     &lt;!-- Enable L2 cache. --&gt;
+ *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
+ *
+ *     &lt;!-- Enable query cache. --&gt;
+ *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
+
+ *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
+ *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
+ *
+ *     &lt;!-- Specify entity. --&gt;
+ *     &lt;mapping class="com.example.Entity"/&gt;
+ *
+ *     &lt;!-- Enable L2 cache with nonstrict-read-write access strategy for entity. --&gt;
+ *     &lt;class-cache class="com.example.Entity" usage="nonstrict-read-write"/&gt;
+ * &lt;/hibernate-configuration&gt;
+ * </pre>
+ * By default queries are not cached even after enabling query caching, to enable results caching for a particular
+ * query, call {@link Query#setCacheable(boolean)}:
+ * <pre name="code" class="java">
+ *     Session ses = getSession();
+ *
+ *     Query qry = ses.createQuery("...");
+ *
+ *     qry.setCacheable(true); // Enable L2 cache for query.
+ * </pre>
+ * Note: the query cache does not cache the state of the actual entities in the cache, it caches only identifier
+ * values. For this reason, the query cache should always be used in conjunction with
+ * the second-level cache for those entities expected to be cached as part of a query result cache
+ */
+class HibernateQueryResultsRegion extends HibernateGeneralDataRegion implements QueryResultsRegion {
+    /**
+     * @param factory Region factory.
+     * @param name Region name.
+     * @param ignite Grid.
+     * @param cache Region cache.
+     */
+    HibernateQueryResultsRegion(HibernateRegionFactory factory, String name,
+        Ignite ignite, HibernateCacheProxy cache) {
+        super(factory, name, ignite, cache);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegion.java b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegion.java
new file mode 100644
index 0000000..3666732
--- /dev/null
+++ b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegion.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.ignite.Ignite;
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.spi.Region;
+
+/**
+ * Implementation of {@link Region}. This interface defines base contract for all L2 cache regions.
+ */
+public class HibernateRegion implements Region {
+    /** */
+    protected final HibernateRegionFactory factory;
+
+    /** */
+    private final String name;
+
+    /** Cache instance. */
+    protected final HibernateCacheProxy cache;
+
+    /** Grid instance. */
+    protected Ignite ignite;
+
+    /**
+     * @param factory Region factory.
+     * @param name Region name.
+     * @param ignite Grid.
+     * @param cache Region cache.
+     */
+    HibernateRegion(HibernateRegionFactory factory, String name, Ignite ignite, HibernateCacheProxy cache) {
+        this.factory = factory;
+        this.name = name;
+        this.ignite = ignite;
+        this.cache = cache;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getName() {
+        return name;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void destroy() throws CacheException {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean contains(Object key) {
+        return cache.containsKey(key);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long getSizeInMemory() {
+        return -1;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long getElementCountInMemory() {
+        return cache.size();
+    }
+
+    /** {@inheritDoc} */
+    @Override public long getElementCountOnDisk() {
+        return -1;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Map toMap() {
+        return Collections.emptyMap();
+    }
+
+    /** {@inheritDoc} */
+    @Override public long nextTimestamp() {
+        return System.currentTimeMillis();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int getTimeout() {
+        return 0;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
new file mode 100644
index 0000000..5667eb2
--- /dev/null
+++ b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import java.util.Properties;
+import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.spi.CacheDataDescription;
+import org.hibernate.cache.spi.CacheKey;
+import org.hibernate.cache.spi.CollectionRegion;
+import org.hibernate.cache.spi.EntityRegion;
+import org.hibernate.cache.spi.NaturalIdRegion;
+import org.hibernate.cache.spi.QueryResultsRegion;
+import org.hibernate.cache.spi.RegionFactory;
+import org.hibernate.cache.spi.TimestampsRegion;
+import org.hibernate.cache.spi.access.AccessType;
+import org.hibernate.cfg.Settings;
+
+import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.DFLT_ACCESS_TYPE_PROPERTY;
+import static org.hibernate.cache.spi.access.AccessType.NONSTRICT_READ_WRITE;
+
+/**
+ * Hibernate L2 cache region factory.
+ * <p>
+ * Following Hibernate settings should be specified to enable second level cache and to use this
+ * region factory for caching:
+ * <pre name="code" class="brush: xml; gutter: false;">
+ * hibernate.cache.use_second_level_cache=true
+ * hibernate.cache.region.factory_class=org.apache.ignite.cache.hibernate.HibernateRegionFactory
+ * </pre>
+ * Note that before region factory is started you need to start properly configured Ignite node in the same JVM.
+ * For example to start Ignite node one of loader provided in {@code org.apache.ignite.grid.startup} package can be used.
+ * <p>
+ * Name of Ignite instance to be used for region factory must be specified as following Hibernate property:
+ * <pre name="code" class="brush: xml; gutter: false;">
+ * org.apache.ignite.hibernate.ignite_instance_name=&lt;Ignite instance name&gt;
+ * </pre>
+ * Each Hibernate cache region must be associated with some {@link IgniteInternalCache}, by default it is assumed that
+ * for each cache region there is a {@link IgniteInternalCache} with the same name. Also it is possible to define
+ * region to cache mapping using properties with prefix {@code org.apache.ignite.hibernate.region_cache}.
+ * For example if for region with name "region1" cache with name "cache1" should be used then following
+ * Hibernate property should be specified:
+ * <pre name="code" class="brush: xml; gutter: false;">
+ * org.apache.ignite.hibernate.region_cache.region1=cache1
+ * </pre>
+ */
+public class HibernateRegionFactory implements RegionFactory {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** */
+    static final HibernateExceptionConverter EXCEPTION_CONVERTER = new HibernateExceptionConverter() {
+        @Override public RuntimeException convert(Exception e) {
+            return new CacheException(e);
+        }
+    };
+
+    /** Default region access type. */
+    private AccessType dfltAccessType;
+
+    /** Key transformer. */
+    private final HibernateKeyTransformer hibernate4transformer = new HibernateKeyTransformer() {
+        @Override public Object transform(Object key) {
+            if (key instanceof CacheKey) {
+                CacheKey cacheKey = (CacheKey)key;
+
+                return new HibernateKeyWrapper(
+                    cacheKey.getKey(),
+                    cacheKey.getEntityOrRoleName(),
+                    cacheKey.getTenantId()
+                );
+            }
+
+            return key;
+        }
+    };
+
+    /** */
+    private final HibernateAccessStrategyFactory accessStgyFactory =
+        new HibernateAccessStrategyFactory(hibernate4transformer, EXCEPTION_CONVERTER);
+
+    /** {@inheritDoc} */
+    @Override public void start(Settings settings, Properties props) throws CacheException {
+        String accessType = props.getProperty(DFLT_ACCESS_TYPE_PROPERTY, NONSTRICT_READ_WRITE.name());
+
+        dfltAccessType = AccessType.valueOf(accessType);
+
+        accessStgyFactory.start(props);
+    }
+
+    /**
+     * @return Access strategy factory.
+     */
+    HibernateAccessStrategyFactory accessStrategyFactory() {
+        return accessStgyFactory;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void stop() {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isMinimalPutsEnabledByDefault() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public AccessType getDefaultAccessType() {
+        return dfltAccessType;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long nextTimestamp() {
+        return System.currentTimeMillis();
+    }
+
+    /** {@inheritDoc} */
+    @Override public EntityRegion buildEntityRegion(String regionName, Properties props, CacheDataDescription metadata)
+        throws CacheException {
+        return new HibernateEntityRegion(this,
+            regionName,
+            accessStgyFactory.node(),
+            accessStgyFactory.regionCache(regionName),
+            metadata);
+    }
+
+    /** {@inheritDoc} */
+    @Override public NaturalIdRegion buildNaturalIdRegion(String regionName, Properties props,
+        CacheDataDescription metadata) throws CacheException {
+        return new HibernateNaturalIdRegion(this,
+            regionName,
+            accessStgyFactory.node(),
+            accessStgyFactory.regionCache(regionName),
+            metadata);
+    }
+
+    /** {@inheritDoc} */
+    @Override public CollectionRegion buildCollectionRegion(String regionName, Properties props,
+        CacheDataDescription metadata) throws CacheException {
+        return new HibernateCollectionRegion(this,
+            regionName,
+            accessStgyFactory.node(),
+            accessStgyFactory.regionCache(regionName),
+            metadata);
+    }
+
+    /** {@inheritDoc} */
+    @Override public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties props)
+        throws CacheException {
+        return new HibernateQueryResultsRegion(this,
+            regionName,
+            accessStgyFactory.node(),
+            accessStgyFactory.regionCache(regionName));
+    }
+
+    /** {@inheritDoc} */
+    @Override public TimestampsRegion buildTimestampsRegion(String regionName, Properties props) throws CacheException {
+        return new HibernateTimestampsRegion(this,
+            regionName,
+            accessStgyFactory.node(),
+            accessStgyFactory.regionCache(regionName));
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateTimestampsRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateTimestampsRegion.java b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateTimestampsRegion.java
new file mode 100644
index 0000000..8b4c243
--- /dev/null
+++ b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateTimestampsRegion.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import org.apache.ignite.Ignite;
+import org.hibernate.cache.spi.TimestampsRegion;
+
+/**
+ * Implementation of {@link TimestampsRegion}. This region is automatically created when query
+ * caching is enabled and it holds most recent updates timestamps to queryable tables.
+ * Name of timestamps region is {@code "org.hibernate.cache.spi.UpdateTimestampsCache"}.
+ */
+public class HibernateTimestampsRegion extends HibernateGeneralDataRegion implements TimestampsRegion {
+    /**
+     * @param factory Region factory.
+     * @param name Region name.
+     * @param ignite Grid.
+     * @param cache Region cache.
+     */
+    public HibernateTimestampsRegion(HibernateRegionFactory factory, String name,
+        Ignite ignite,  HibernateCacheProxy cache) {
+        super(factory, name, ignite, cache);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java
new file mode 100644
index 0000000..275ea9e
--- /dev/null
+++ b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import org.apache.ignite.Ignite;
+import org.hibernate.cache.spi.CacheDataDescription;
+import org.hibernate.cache.spi.CollectionRegion;
+import org.hibernate.cache.spi.EntityRegion;
+import org.hibernate.cache.spi.NaturalIdRegion;
+import org.hibernate.cache.spi.TransactionalDataRegion;
+import org.hibernate.cache.spi.access.AccessType;
+
+/**
+ * Implementation of {@link TransactionalDataRegion} (transactional means that
+ * data in the region is updated in connection with database transaction).
+ * This interface defines base contract for {@link EntityRegion}, {@link CollectionRegion}
+ * and {@link NaturalIdRegion}.
+ */
+public class HibernateTransactionalDataRegion extends HibernateRegion implements TransactionalDataRegion {
+    /** */
+    private final CacheDataDescription dataDesc;
+
+    /**
+     * @param factory Region factory.
+     * @param name Region name.
+     * @param ignite Grid.
+     * @param cache Region cache.
+     * @param dataDesc Region data description.
+     */
+    HibernateTransactionalDataRegion(HibernateRegionFactory factory, String name,
+        Ignite ignite, HibernateCacheProxy cache, CacheDataDescription dataDesc) {
+        super(factory, name, ignite, cache);
+
+        this.dataDesc = dataDesc;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isTransactionAware() {
+        return false; // This method is not used by Hibernate.
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheDataDescription getCacheDataDescription() {
+        return dataDesc;
+    }
+
+    /**
+     * @param accessType Hibernate L2 cache access type.
+     * @return Access strategy for given access type.
+     */
+    HibernateAccessStrategyAdapter createAccessStrategy(AccessType accessType) {
+        switch (accessType) {
+            case READ_ONLY:
+                return factory.accessStrategyFactory().createReadOnlyStrategy(cache);
+
+            case NONSTRICT_READ_WRITE:
+                return factory.accessStrategyFactory().createNonStrictReadWriteStrategy(cache);
+
+            case READ_WRITE:
+                return factory.accessStrategyFactory().createReadWriteStrategy(cache);
+
+            case TRANSACTIONAL:
+                return factory.accessStrategyFactory().createTransactionalStrategy(cache);
+
+            default:
+                throw new IllegalArgumentException("Unknown Hibernate access type: " + accessType);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/package-info.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/package-info.java b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/package-info.java
new file mode 100644
index 0000000..1179aec
--- /dev/null
+++ b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/hibernate/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * <!-- Package description. -->
+ * Contains implementation of Hibernate L2 cache. Refer to
+ * <i>org.apache.ignite.examples.datagrid.hibernate.HibernateL2CacheExample</i> for more information on how to
+ * configure and use Ignite with Hibernate.
+ */
+package org.apache.ignite.cache.hibernate;
\ No newline at end of file


[15/16] ignite git commit: ignite-1794 Refactored hibernate modules, switched to hibernate 5.1

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java
new file mode 100644
index 0000000..c87f08f
--- /dev/null
+++ b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java
@@ -0,0 +1,542 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.store.hibernate;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.cache.integration.CacheLoaderException;
+import javax.cache.integration.CacheWriterException;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cache.store.CacheStore;
+import org.apache.ignite.cache.store.CacheStoreAdapter;
+import org.apache.ignite.cache.store.CacheStoreSession;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.util.tostring.GridToStringExclude;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.marshaller.jdk.JdkMarshaller;
+import org.apache.ignite.resources.CacheStoreSessionResource;
+import org.apache.ignite.resources.IgniteInstanceResource;
+import org.apache.ignite.resources.LoggerResource;
+import org.apache.ignite.transactions.Transaction;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.SharedSessionContract;
+import org.hibernate.cfg.Configuration;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * {@link CacheStore} implementation backed by Hibernate. This implementation
+ * stores objects in underlying database in {@code BLOB} format.
+ * <h2 class="header">Configuration</h2>
+ * Either {@link #setSessionFactory(SessionFactory)} or
+ * {@link #setHibernateConfigurationPath(String)} or
+ * {@link #setHibernateProperties(Properties)} should be set.
+ * <p>
+ * If session factory is provided it should contain
+ * {@link CacheHibernateBlobStoreEntry} persistent class (via provided
+ * mapping file {@code GridCacheHibernateStoreEntry.hbm.xml} or by
+ * adding {@link CacheHibernateBlobStoreEntry} to annotated classes
+ * of session factory.
+ * <p>
+ * Path to hibernate configuration may be either an URL or a file path or
+ * a classpath resource. This configuration file should include provided
+ * mapping {@code GridCacheHibernateStoreEntry.hbm.xml} or include annotated
+ * class {@link CacheHibernateBlobStoreEntry}.
+ * <p>
+ * If hibernate properties are provided, mapping
+ * {@code GridCacheHibernateStoreEntry.hbm.xml} is included automatically.
+ * <p>
+ * Use {@link CacheHibernateBlobStoreFactory} factory to pass {@link CacheHibernateBlobStore} to {@link CacheConfiguration}.
+ */
+public class CacheHibernateBlobStore<K, V> extends CacheStoreAdapter<K, V> {
+    /**
+     * Default connection URL
+     * (value is <tt>jdbc:h2:mem:hibernateCacheStore;DB_CLOSE_DELAY=-1;DEFAULT_LOCK_TIMEOUT=5000</tt>).
+     */
+    public static final String DFLT_CONN_URL = "jdbc:h2:mem:hibernateCacheStore;DB_CLOSE_DELAY=-1;" +
+        "DEFAULT_LOCK_TIMEOUT=5000";
+
+    /** Default show SQL property value (value is <tt>true</tt>). */
+    public static final String DFLT_SHOW_SQL = "true";
+
+    /** Default <tt>hibernate.hbm2ddl.auto</tt> property value (value is <tt>true</tt>). */
+    public static final String DFLT_HBM2DDL_AUTO = "update";
+
+    /** Session attribute name. */
+    private static final String ATTR_SES = "HIBERNATE_STORE_SESSION";
+
+    /** Name of Hibarname mapping resource. */
+    private static final String MAPPING_RESOURCE =
+            "org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml";
+
+    /** Marshaller. */
+    private static final Marshaller marsh = new JdkMarshaller();
+
+    /** Init guard. */
+    @GridToStringExclude
+    private final AtomicBoolean initGuard = new AtomicBoolean();
+
+    /** Init latch. */
+    @GridToStringExclude
+    private final CountDownLatch initLatch = new CountDownLatch(1);
+
+    /** Hibernate properties. */
+    @GridToStringExclude
+    private Properties hibernateProps;
+
+    /** Session factory. */
+    @GridToStringExclude
+    private SessionFactory sesFactory;
+
+    /** Path to hibernate configuration file. */
+    private String hibernateCfgPath;
+
+    /** Log. */
+    @LoggerResource
+    private IgniteLogger log;
+
+    /** Auto-injected store session. */
+    @CacheStoreSessionResource
+    private CacheStoreSession ses;
+
+    /** Ignite instance. */
+    @IgniteInstanceResource
+    private Ignite ignite;
+
+    /** {@inheritDoc} */
+    @SuppressWarnings({"unchecked", "RedundantTypeArguments"})
+    @Override public V load(K key) {
+        init();
+
+        Transaction tx = transaction();
+
+        if (log.isDebugEnabled())
+            log.debug("Store load [key=" + key + ", tx=" + tx + ']');
+
+        Session ses = session(tx);
+
+        try {
+            CacheHibernateBlobStoreEntry entry = (CacheHibernateBlobStoreEntry)
+                ses.get(CacheHibernateBlobStoreEntry.class, toBytes(key));
+
+            if (entry == null)
+                return null;
+
+            return fromBytes(entry.getValue());
+        }
+        catch (IgniteCheckedException | HibernateException e) {
+            rollback(ses, tx);
+
+            throw new CacheLoaderException("Failed to load value from cache store with key: " + key, e);
+        }
+        finally {
+            end(ses, tx);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void write(javax.cache.Cache.Entry<? extends K, ? extends V> entry) {
+        init();
+
+        Transaction tx = transaction();
+
+        K key = entry.getKey();
+        V val = entry.getValue();
+
+        if (log.isDebugEnabled())
+            log.debug("Store put [key=" + key + ", val=" + val + ", tx=" + tx + ']');
+
+        if (val == null) {
+            delete(key);
+
+            return;
+        }
+
+        Session ses = session(tx);
+
+        try {
+            CacheHibernateBlobStoreEntry entry0 = new CacheHibernateBlobStoreEntry(toBytes(key), toBytes(val));
+
+            ses.saveOrUpdate(entry0);
+        }
+        catch (IgniteCheckedException | HibernateException e) {
+            rollback(ses, tx);
+
+            throw new CacheWriterException("Failed to put value to cache store [key=" + key + ", val" + val + "]", e);
+        }
+        finally {
+            end(ses, tx);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings({"JpaQueryApiInspection", "JpaQlInspection"})
+    @Override public void delete(Object key) {
+        init();
+
+        Transaction tx = transaction();
+
+        if (log.isDebugEnabled())
+            log.debug("Store remove [key=" + key + ", tx=" + tx + ']');
+
+        Session ses = session(tx);
+
+        try {
+            Object obj = ses.get(CacheHibernateBlobStoreEntry.class, toBytes(key));
+
+            if (obj != null)
+                ses.delete(obj);
+        }
+        catch (IgniteCheckedException | HibernateException e) {
+            rollback(ses, tx);
+
+            throw new CacheWriterException("Failed to remove value from cache store with key: " + key, e);
+        }
+        finally {
+            end(ses, tx);
+        }
+    }
+
+    /**
+     * Rolls back hibernate session.
+     *
+     * @param ses Hibernate session.
+     * @param tx Cache ongoing transaction.
+     */
+    private void rollback(SharedSessionContract ses, Transaction tx) {
+        // Rollback only if there is no cache transaction,
+        // otherwise sessionEnd() will do all required work.
+        if (tx == null) {
+            org.hibernate.Transaction hTx = ses.getTransaction();
+
+            if (hTx != null && hTx.isActive())
+                hTx.rollback();
+        }
+    }
+
+    /**
+     * Ends hibernate session.
+     *
+     * @param ses Hibernate session.
+     * @param tx Cache ongoing transaction.
+     */
+    private void end(Session ses, Transaction tx) {
+        // Commit only if there is no cache transaction,
+        // otherwise sessionEnd() will do all required work.
+        if (tx == null) {
+            org.hibernate.Transaction hTx = ses.getTransaction();
+
+            if (hTx != null && hTx.isActive())
+                hTx.commit();
+
+            ses.close();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void sessionEnd(boolean commit) {
+        init();
+
+        Transaction tx = transaction();
+
+        Map<String, Session> props = session().properties();
+
+        Session ses = props.remove(ATTR_SES);
+
+        if (ses != null) {
+            org.hibernate.Transaction hTx = ses.getTransaction();
+
+            if (hTx != null) {
+                try {
+                    if (commit) {
+                        ses.flush();
+
+                        hTx.commit();
+                    }
+                    else
+                        hTx.rollback();
+
+                    if (log.isDebugEnabled())
+                        log.debug("Transaction ended [xid=" + tx.xid() + ", commit=" + commit + ']');
+                }
+                catch (HibernateException e) {
+                    throw new CacheWriterException("Failed to end transaction [xid=" + tx.xid() +
+                        ", commit=" + commit + ']', e);
+                }
+                finally {
+                    ses.close();
+                }
+            }
+        }
+    }
+
+    /**
+     * Gets Hibernate session.
+     *
+     * @param tx Cache transaction.
+     * @return Session.
+     */
+    Session session(@Nullable Transaction tx) {
+        Session ses;
+
+        if (tx != null) {
+            Map<String, Session> props = session().properties();
+
+            ses = props.get(ATTR_SES);
+
+            if (ses == null) {
+                ses = sesFactory.openSession();
+
+                ses.beginTransaction();
+
+                // Store session in transaction metadata, so it can be accessed
+                // for other operations on the same transaction.
+                props.put(ATTR_SES, ses);
+
+                if (log.isDebugEnabled())
+                    log.debug("Hibernate session open [ses=" + ses + ", tx=" + tx.xid() + "]");
+            }
+        }
+        else {
+            ses = sesFactory.openSession();
+
+            ses.beginTransaction();
+        }
+
+        return ses;
+    }
+
+    /**
+     * Sets session factory.
+     *
+     * @param sesFactory Session factory.
+     */
+    public void setSessionFactory(SessionFactory sesFactory) {
+        this.sesFactory = sesFactory;
+    }
+
+    /**
+     * Sets hibernate configuration path.
+     * <p>
+     * This may be either URL or file path or classpath resource.
+     *
+     * @param hibernateCfgPath URL or file path or classpath resource
+     *      pointing to hibernate configuration XML file.
+     */
+    public void setHibernateConfigurationPath(String hibernateCfgPath) {
+        this.hibernateCfgPath = hibernateCfgPath;
+    }
+
+    /**
+     * Sets Hibernate properties.
+     *
+     * @param hibernateProps Hibernate properties.
+     */
+    public void setHibernateProperties(Properties hibernateProps) {
+        this.hibernateProps = hibernateProps;
+    }
+
+    /**
+     * Initializes store.
+     *
+     * @throws IgniteException If failed to initialize.
+     */
+    private void init() throws IgniteException {
+        if (initGuard.compareAndSet(false, true)) {
+            if (log.isDebugEnabled())
+                log.debug("Initializing cache store.");
+
+            try {
+                if (sesFactory != null)
+                    // Session factory has been provided - nothing to do.
+                    return;
+
+                if (!F.isEmpty(hibernateCfgPath)) {
+                    try {
+                        URL url = new URL(hibernateCfgPath);
+
+                        sesFactory = new Configuration().configure(url).buildSessionFactory();
+
+                        if (log.isDebugEnabled())
+                            log.debug("Configured session factory using URL: " + url);
+
+                        // Session factory has been successfully initialized.
+                        return;
+                    }
+                    catch (MalformedURLException e) {
+                        if (log.isDebugEnabled())
+                            log.debug("Caught malformed URL exception: " + e.getMessage());
+                    }
+
+                    // Provided path is not a valid URL. File?
+                    File cfgFile = new File(hibernateCfgPath);
+
+                    if (cfgFile.exists()) {
+                        sesFactory = new Configuration().configure(cfgFile).buildSessionFactory();
+
+                        if (log.isDebugEnabled())
+                            log.debug("Configured session factory using file: " + hibernateCfgPath);
+
+                        // Session factory has been successfully initialized.
+                        return;
+                    }
+
+                    // Provided path is not a file. Classpath resource?
+                    sesFactory = new Configuration().configure(hibernateCfgPath).buildSessionFactory();
+
+                    if (log.isDebugEnabled())
+                        log.debug("Configured session factory using classpath resource: " + hibernateCfgPath);
+                }
+                else {
+                    if (hibernateProps == null) {
+                        U.warn(log, "No Hibernate configuration has been provided for store (will use default).");
+
+                        hibernateProps = new Properties();
+
+                        hibernateProps.setProperty("hibernate.connection.url", DFLT_CONN_URL);
+                        hibernateProps.setProperty("hibernate.show_sql", DFLT_SHOW_SQL);
+                        hibernateProps.setProperty("hibernate.hbm2ddl.auto", DFLT_HBM2DDL_AUTO);
+                    }
+
+                    Configuration cfg = new Configuration();
+
+                    cfg.setProperties(hibernateProps);
+
+                    assert resourceAvailable(MAPPING_RESOURCE) : MAPPING_RESOURCE;
+
+                    cfg.addResource(MAPPING_RESOURCE);
+
+                    sesFactory = cfg.buildSessionFactory();
+
+                    if (log.isDebugEnabled())
+                        log.debug("Configured session factory using properties: " + hibernateProps);
+                }
+            }
+            catch (HibernateException e) {
+                throw new IgniteException("Failed to initialize store.", e);
+            }
+            finally {
+                initLatch.countDown();
+            }
+        }
+        else if (initLatch.getCount() > 0) {
+            try {
+                U.await(initLatch);
+            }
+            catch (IgniteInterruptedCheckedException e) {
+                throw new IgniteException(e);
+            }
+        }
+
+        if (sesFactory == null)
+            throw new IgniteException("Cache store was not properly initialized.");
+    }
+
+    /**
+     * Checks availability of a classpath resource.
+     *
+     * @param name Resource name.
+     * @return {@code true} if resource is available and ready for read, {@code false} otherwise.
+     */
+    private boolean resourceAvailable(String name) {
+        InputStream cfgStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
+
+        if (cfgStream == null) {
+            log.error("Classpath resource not found: " + name);
+
+            return false;
+        }
+
+        try {
+            // Read a single byte to force actual content access by JVM.
+            cfgStream.read();
+
+            return true;
+        }
+        catch (IOException e) {
+            log.error("Failed to read classpath resource: " + name, e);
+
+            return false;
+        }
+        finally {
+            U.close(cfgStream, log);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(CacheHibernateBlobStore.class, this);
+    }
+
+    /**
+     * Serialize object to byte array using marshaller.
+     *
+     * @param obj Object to convert to byte array.
+     * @return Byte array.
+     * @throws IgniteCheckedException If failed to convert.
+     */
+    protected byte[] toBytes(Object obj) throws IgniteCheckedException {
+        return U.marshal(marsh, obj);
+    }
+
+    /**
+     * Deserialize object from byte array using marshaller.
+     *
+     * @param bytes Bytes to deserialize.
+     * @param <X> Result object type.
+     * @return Deserialized object.
+     * @throws IgniteCheckedException If failed.
+     */
+    protected <X> X fromBytes(byte[] bytes) throws IgniteCheckedException {
+        if (bytes == null || bytes.length == 0)
+            return null;
+
+        return U.unmarshal(marsh, bytes, getClass().getClassLoader());
+    }
+
+    /**
+     * @return Current transaction.
+     */
+    @Nullable private Transaction transaction() {
+        CacheStoreSession ses = session();
+
+        return ses != null ? ses.transaction() : null;
+    }
+
+    /**
+     * @return Store session.
+     */
+    private CacheStoreSession session() {
+        return ses;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml
new file mode 100644
index 0000000..5b0be43
--- /dev/null
+++ b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+
+<!DOCTYPE hibernate-mapping PUBLIC
+        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.apache.ignite.examples.datagrid.store" default-access="field">
+    <class name="org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreEntry" table="ENTRIES">
+        <id name="key"/>
+
+        <property name="val"/>
+    </class>
+</hibernate-mapping>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.java b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.java
new file mode 100644
index 0000000..d40c5ef
--- /dev/null
+++ b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.store.hibernate;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+/**
+ * Entry that is used by {@link CacheHibernateBlobStore} implementation.
+ * <p>
+ * Note that this is a reference implementation for tests only.
+ * When running on production systems use concrete key-value types to
+ * get better performance.
+ */
+@Entity
+@Table(name = "ENTRIES")
+public class CacheHibernateBlobStoreEntry {
+    /** Key (use concrete key type in production). */
+    @Id
+    @Column(length = 65535)
+    private byte[] key;
+
+    /** Value (use concrete value type in production). */
+    @Column(length = 65535)
+    private byte[] val;
+
+    /**
+     * Constructor.
+     */
+    CacheHibernateBlobStoreEntry() {
+        // No-op.
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param key Key.
+     * @param val Value.
+     */
+    CacheHibernateBlobStoreEntry(byte[] key, byte[] val) {
+        this.key = key;
+        this.val = val;
+    }
+
+    /**
+     * @return Key.
+     */
+    public byte[] getKey() {
+        return key;
+    }
+
+    /**
+     * @param key Key.
+     */
+    public void setKey(byte[] key) {
+        this.key = key;
+    }
+
+    /**
+     * @return Value.
+     */
+    public byte[] getValue() {
+        return val;
+    }
+
+    /**
+     * @param val Value.
+     */
+    public void setValue(byte[] val) {
+        this.val = val;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreFactory.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreFactory.java b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreFactory.java
new file mode 100644
index 0000000..ea4df8a
--- /dev/null
+++ b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreFactory.java
@@ -0,0 +1,235 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.store.hibernate;
+
+import java.util.Properties;
+import javax.cache.configuration.Factory;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.IgniteComponentType;
+import org.apache.ignite.internal.util.spring.IgniteSpringHelper;
+import org.apache.ignite.internal.util.tostring.GridToStringExclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.resources.SpringApplicationContextResource;
+import org.hibernate.SessionFactory;
+
+/**
+ * {@link Factory} implementation for {@link CacheHibernateBlobStore}.
+ *
+ * Use this factory to pass {@link CacheHibernateBlobStore} to {@link CacheConfiguration}.
+ *
+ * <h2 class="header">Java Example</h2>
+ * In this example existing session factory is provided.
+ * <pre name="code" class="java">
+ *     ...
+ *     CacheHibernateBlobStoreFactory&lt;String, String&gt; factory = new CacheHibernateBlobStoreFactory&lt;String, String&gt;();
+ *
+ *     factory.setSessionFactory(sesFactory);
+ *     ...
+ * </pre>
+ *
+ * <h2 class="header">Spring Example (using Spring ORM)</h2>
+ * <pre name="code" class="xml">
+ *   ...
+ *   &lt;bean id=&quot;cache.hibernate.store.factory&quot;
+ *       class=&quot;org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory&quot;&gt;
+ *       &lt;property name=&quot;sessionFactory&quot;&gt;
+ *           &lt;bean class=&quot;org.springframework.orm.hibernate3.LocalSessionFactoryBean&quot;&gt;
+ *               &lt;property name=&quot;hibernateProperties&quot;&gt;
+ *                   &lt;value&gt;
+ *                       connection.url=jdbc:h2:mem:
+ *                       show_sql=true
+ *                       hbm2ddl.auto=true
+ *                       hibernate.dialect=org.hibernate.dialect.H2Dialect
+ *                   &lt;/value&gt;
+ *               &lt;/property&gt;
+ *               &lt;property name=&quot;mappingResources&quot;&gt;
+ *                   &lt;list&gt;
+ *                       &lt;value&gt;
+ *                           org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml
+ *                       &lt;/value&gt;
+ *                   &lt;/list&gt;
+ *               &lt;/property&gt;
+ *           &lt;/bean&gt;
+ *       &lt;/property&gt;
+ *   &lt;/bean&gt;
+ *   ...
+ * </pre>
+ *
+ * <h2 class="header">Spring Example (using Spring ORM and persistent annotations)</h2>
+ * <pre name="code" class="xml">
+ *     ...
+ *     &lt;bean id=&quot;cache.hibernate.store.factory1&quot;
+ *         class=&quot;org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory&quot;&gt;
+ *         &lt;property name=&quot;sessionFactory&quot;&gt;
+ *             &lt;bean class=&quot;org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean&quot;&gt;
+ *                 &lt;property name=&quot;hibernateProperties&quot;&gt;
+ *                     &lt;value&gt;
+ *                         connection.url=jdbc:h2:mem:
+ *                         show_sql=true
+ *                         hbm2ddl.auto=true
+ *                         hibernate.dialect=org.hibernate.dialect.H2Dialect
+ *                     &lt;/value&gt;
+ *                 &lt;/property&gt;
+ *                 &lt;property name=&quot;annotatedClasses&quot;&gt;
+ *                     &lt;list&gt;
+ *                         &lt;value&gt;
+ *                             org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreEntry
+ *                         &lt;/value&gt;
+ *                     &lt;/list&gt;
+ *                 &lt;/property&gt;
+ *             &lt;/bean&gt;
+ *         &lt;/property&gt;
+ *     &lt;/bean&gt;
+ *     ...
+ * </pre>
+ *
+ * <h2 class="header">Spring Example</h2>
+ * <pre name="code" class="xml">
+ *     ...
+ *     &lt;bean id=&quot;cache.hibernate.store.factory2&quot;
+ *         class=&quot;org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory&quot;&gt;
+ *         &lt;property name=&quot;hibernateProperties&quot;&gt;
+ *             &lt;props&gt;
+ *                 &lt;prop key=&quot;connection.url&quot;&gt;jdbc:h2:mem:&lt;/prop&gt;
+ *                 &lt;prop key=&quot;hbm2ddl.auto&quot;&gt;update&lt;/prop&gt;
+ *                 &lt;prop key=&quot;show_sql&quot;&gt;true&lt;/prop&gt;
+ *             &lt;/props&gt;
+ *         &lt;/property&gt;
+ *     &lt;/bean&gt;
+ *     ...
+ * </pre>
+ * <p>
+ * <img src="http://ignite.apache.org/images/spring-small.png">
+ * <br>
+ * For information about Spring framework visit <a href="http://www.springframework.org/">www.springframework.org</a>
+ */
+public class CacheHibernateBlobStoreFactory<K, V> implements Factory<CacheHibernateBlobStore<K, V>> {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Session factory. */
+    @GridToStringExclude
+    private transient SessionFactory sesFactory;
+
+    /** Session factory bean name. */
+    private String sesFactoryBean;
+
+    /** Path to hibernate configuration file. */
+    private String hibernateCfgPath;
+
+    /** Hibernate properties. */
+    @GridToStringExclude
+    private Properties hibernateProps;
+
+    /** Application context. */
+    @SpringApplicationContextResource
+    private Object appContext;
+
+    /** {@inheritDoc} */
+    @Override public CacheHibernateBlobStore<K, V> create() {
+        CacheHibernateBlobStore<K, V> store = new CacheHibernateBlobStore<>();
+
+        store.setHibernateConfigurationPath(hibernateCfgPath);
+        store.setHibernateProperties(hibernateProps);
+
+        if (sesFactory != null)
+            store.setSessionFactory(sesFactory);
+        else if (sesFactoryBean != null) {
+            if (appContext == null)
+                throw new IgniteException("Spring application context resource is not injected.");
+
+            IgniteSpringHelper spring;
+
+            try {
+                spring = IgniteComponentType.SPRING.create(false);
+
+                SessionFactory sesFac = spring.loadBeanFromAppContext(appContext, sesFactoryBean);
+
+                store.setSessionFactory(sesFac);
+            }
+            catch (IgniteCheckedException e) {
+                throw new IgniteException("Failed to load bean in application context [beanName=" + sesFactoryBean +
+                        ", igniteConfig=" + appContext + ']');
+            }
+        }
+
+        return store;
+    }
+
+    /**
+     * Sets session factory.
+     *
+     * @param sesFactory Session factory.
+     * @return {@code This} for chaining.
+     * @see CacheHibernateBlobStore#setSessionFactory(SessionFactory)
+     */
+    public CacheHibernateBlobStoreFactory<K, V> setSessionFactory(SessionFactory sesFactory) {
+        this.sesFactory = sesFactory;
+
+        return this;
+    }
+
+    /**
+     * Sets name of the data source bean.
+     *
+     * @param sesFactory Session factory bean name.
+     * @return {@code This} for chaining.
+     * @see CacheHibernateBlobStore#setSessionFactory(SessionFactory)
+     */
+    public CacheHibernateBlobStoreFactory<K, V> setSessionFactoryBean(String sesFactory) {
+        this.sesFactoryBean = sesFactory;
+
+        return this;
+    }
+
+    /**
+     * Sets hibernate configuration path.
+     * <p>
+     * This may be either URL or file path or classpath resource.
+     *
+     * @param hibernateCfgPath URL or file path or classpath resource
+     *      pointing to hibernate configuration XML file.
+     * @return {@code This} for chaining.
+     * @see CacheHibernateBlobStore#setHibernateConfigurationPath(String)
+     */
+    public CacheHibernateBlobStoreFactory<K, V> setHibernateConfigurationPath(String hibernateCfgPath) {
+        this.hibernateCfgPath = hibernateCfgPath;
+
+        return this;
+    }
+
+    /**
+     * Sets Hibernate properties.
+     *
+     * @param hibernateProps Hibernate properties.
+     * @return {@code This} for chaining.
+     * @see CacheHibernateBlobStore#setHibernateProperties(Properties)
+     */
+    public CacheHibernateBlobStoreFactory<K, V> setHibernateProperties(Properties hibernateProps) {
+        this.hibernateProps = hibernateProps;
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(CacheHibernateBlobStoreFactory.class, this);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java
new file mode 100644
index 0000000..917641c
--- /dev/null
+++ b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.store.hibernate;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import javax.cache.integration.CacheWriterException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cache.store.CacheStore;
+import org.apache.ignite.cache.store.CacheStoreSession;
+import org.apache.ignite.cache.store.CacheStoreSessionListener;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lifecycle.LifecycleAware;
+import org.apache.ignite.resources.LoggerResource;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+
+/**
+ * Hibernate-based cache store session listener.
+ * <p>
+ * This listener creates a new Hibernate session for each store
+ * session. If there is an ongoing cache transaction, a corresponding
+ * Hibernate transaction is created as well.
+ * <p>
+ * The Hibernate session is saved as a store session
+ * {@link CacheStoreSession#attachment() attachment}.
+ * The listener guarantees that the session will be
+ * available for any store operation. If there is an
+ * ongoing cache transaction, all operations within this
+ * transaction will share a DB transaction.
+ * <p>
+ * As an example, here is how the {@link CacheStore#write(javax.cache.Cache.Entry)}
+ * method can be implemented if {@link CacheHibernateStoreSessionListener}
+ * is configured:
+ * <pre name="code" class="java">
+ * private static class Store extends CacheStoreAdapter&lt;Integer, Integer&gt; {
+ *     &#64;CacheStoreSessionResource
+ *     private CacheStoreSession ses;
+ *
+ *     &#64;Override public void write(Cache.Entry&lt;? extends Integer, ? extends Integer&gt; entry) throws CacheWriterException {
+ *         // Get Hibernate session from the current store session.
+ *         Session hibSes = ses.attachment();
+ *
+ *         // Persist the value.
+ *         hibSes.persist(entry.getValue());
+ *     }
+ * }
+ * </pre>
+ * Hibernate session will be automatically created by the listener
+ * at the start of the session and closed when it ends.
+ * <p>
+ * {@link CacheHibernateStoreSessionListener} requires that either
+ * {@link #setSessionFactory(SessionFactory)} session factory}
+ * or {@link #setHibernateConfigurationPath(String) Hibernate configuration file}
+ * is provided. If non of them is set, exception is thrown. Is both are provided,
+ * session factory will be used.
+ */
+public class CacheHibernateStoreSessionListener implements CacheStoreSessionListener, LifecycleAware {
+    /** Hibernate session factory. */
+    private SessionFactory sesFactory;
+
+    /** Hibernate configuration file path. */
+    private String hibernateCfgPath;
+
+    /** Logger. */
+    @LoggerResource
+    private IgniteLogger log;
+
+    /** Whether to close session on stop. */
+    private boolean closeSesOnStop;
+
+    /**
+     * Sets Hibernate session factory.
+     * <p>
+     * Either session factory or configuration file is required.
+     * If none is provided, exception will be thrown on startup.
+     *
+     * @param sesFactory Session factory.
+     */
+    public void setSessionFactory(SessionFactory sesFactory) {
+        this.sesFactory = sesFactory;
+    }
+
+    /**
+     * Gets Hibernate session factory.
+     *
+     * @return Session factory.
+     */
+    public SessionFactory getSessionFactory() {
+        return sesFactory;
+    }
+
+    /**
+     * Sets hibernate configuration path.
+     * <p>
+     * Either session factory or configuration file is required.
+     * If none is provided, exception will be thrown on startup.
+     *
+     * @param hibernateCfgPath Hibernate configuration path.
+     */
+    public void setHibernateConfigurationPath(String hibernateCfgPath) {
+        this.hibernateCfgPath = hibernateCfgPath;
+    }
+
+    /**
+     * Gets hibernate configuration path.
+     *
+     * @return Hibernate configuration path.
+     */
+    public String getHibernateConfigurationPath() {
+        return hibernateCfgPath;
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("deprecation")
+    @Override public void start() throws IgniteException {
+        if (sesFactory == null && F.isEmpty(hibernateCfgPath))
+            throw new IgniteException("Either session factory or Hibernate configuration file is required by " +
+                getClass().getSimpleName() + '.');
+
+        if (!F.isEmpty(hibernateCfgPath)) {
+            if (sesFactory == null) {
+                try {
+                    URL url = new URL(hibernateCfgPath);
+
+                    sesFactory = new Configuration().configure(url).buildSessionFactory();
+                }
+                catch (MalformedURLException ignored) {
+                    // No-op.
+                }
+
+                if (sesFactory == null) {
+                    File cfgFile = new File(hibernateCfgPath);
+
+                    if (cfgFile.exists())
+                        sesFactory = new Configuration().configure(cfgFile).buildSessionFactory();
+                }
+
+                if (sesFactory == null)
+                    sesFactory = new Configuration().configure(hibernateCfgPath).buildSessionFactory();
+
+                if (sesFactory == null)
+                    throw new IgniteException("Failed to resolve Hibernate configuration file: " + hibernateCfgPath);
+
+                closeSesOnStop = true;
+            }
+            else
+                U.warn(log, "Hibernate configuration file configured in " + getClass().getSimpleName() +
+                    " will be ignored (session factory is already set).");
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void stop() throws IgniteException {
+        if (closeSesOnStop && sesFactory != null && !sesFactory.isClosed())
+            sesFactory.close();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onSessionStart(CacheStoreSession ses) {
+        if (ses.attachment() == null) {
+            try {
+                Session hibSes = sesFactory.openSession();
+
+                ses.attach(hibSes);
+
+                if (ses.isWithinTransaction())
+                    hibSes.beginTransaction();
+            }
+            catch (HibernateException e) {
+                throw new CacheWriterException("Failed to start store session [tx=" + ses.transaction() + ']', e);
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onSessionEnd(CacheStoreSession ses, boolean commit) {
+        Session hibSes = ses.attach(null);
+
+        if (hibSes != null) {
+            try {
+                Transaction tx = hibSes.getTransaction();
+
+                if (commit) {
+                    hibSes.flush();
+
+                    if (tx.isActive())
+                        tx.commit();
+                }
+                else if (tx.isActive())
+                    tx.rollback();
+            }
+            catch (HibernateException e) {
+                throw new CacheWriterException("Failed to end store session [tx=" + ses.transaction() + ']', e);
+            }
+            finally {
+                hibSes.close();
+            }
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/package-info.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/package-info.java b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/package-info.java
new file mode 100644
index 0000000..891d99a
--- /dev/null
+++ b/modules/hibernate-4.2/src/main/java/org/apache/ignite/cache/store/hibernate/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * <!-- Package description. -->
+ * Contains reference Hibernate-based cache store implementation.
+ */
+package org.apache.ignite.cache.store.hibernate;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/config/factory-cache.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/test/config/factory-cache.xml b/modules/hibernate-4.2/src/test/config/factory-cache.xml
new file mode 100644
index 0000000..a251846
--- /dev/null
+++ b/modules/hibernate-4.2/src/test/config/factory-cache.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+        http://www.springframework.org/schema/beans
+        http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+    <bean id="simpleSessionFactory"
+          class="org.apache.ignite.cache.store.hibernate.CacheHibernateStoreFactorySelfTest$DummySessionFactoryExt"/>
+
+    <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+        <property name="cacheConfiguration">
+            <list>
+                <bean class="org.apache.ignite.configuration.CacheConfiguration">
+                    <property name="name" value="test"/>
+                    <property name="atomicityMode" value="ATOMIC"/>
+                    <property name="backups" value="1"/>
+                    <property name="cacheStoreFactory">
+                        <bean class="org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory">
+                            <property name="sessionFactoryBean" value = "simpleSessionFactory"/>
+                        </bean>
+                    </property>
+                </bean>
+            </list>
+        </property>
+
+        <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
+        <property name="discoverySpi">
+            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+                <property name="ipFinder">
+                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
+                        <property name="addresses">
+                            <list>
+                                <value>127.0.0.1:47500..47509</value>
+                            </list>
+                        </property>
+                    </bean>
+                </property>
+            </bean>
+        </property>
+    </bean>
+</beans>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/config/factory-cache1.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/test/config/factory-cache1.xml b/modules/hibernate-4.2/src/test/config/factory-cache1.xml
new file mode 100644
index 0000000..7a53b1f
--- /dev/null
+++ b/modules/hibernate-4.2/src/test/config/factory-cache1.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+        http://www.springframework.org/schema/beans
+        http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+    <bean id="simpleSessionFactory1"
+          class="org.apache.ignite.cache.store.hibernate.CacheHibernateStoreFactorySelfTest$DummySessionFactory"/>
+
+    <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+        <property name="igniteInstanceName" value="ignite1"/>
+
+        <property name="cacheConfiguration">
+            <list>
+                <bean class="org.apache.ignite.configuration.CacheConfiguration">
+                    <property name="name" value="test"/>
+                    <property name="atomicityMode" value="ATOMIC"/>
+                    <property name="backups" value="1"/>
+                    <property name="cacheStoreFactory">
+                        <bean class="org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory">
+                            <property name="sessionFactoryBean" value = "simpleSessionFactory1"/>
+                        </bean>
+                    </property>
+                </bean>
+            </list>
+        </property>
+
+        <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
+        <property name="discoverySpi">
+            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+                <property name="ipFinder">
+                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
+                        <property name="addresses">
+                            <list>
+                                <value>127.0.0.1:47500..47509</value>
+                            </list>
+                        </property>
+                    </bean>
+                </property>
+            </bean>
+        </property>
+    </bean>
+</beans>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/config/factory-incorrect-store-cache.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/test/config/factory-incorrect-store-cache.xml b/modules/hibernate-4.2/src/test/config/factory-incorrect-store-cache.xml
new file mode 100644
index 0000000..459930c
--- /dev/null
+++ b/modules/hibernate-4.2/src/test/config/factory-incorrect-store-cache.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+        http://www.springframework.org/schema/beans
+        http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+    <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+        <property name="cacheConfiguration">
+            <list>
+                <bean class="org.apache.ignite.configuration.CacheConfiguration">
+                    <property name="name" value="test"/>
+                    <property name="atomicityMode" value="ATOMIC"/>
+                    <property name="backups" value="1"/>
+                    <property name="cacheStoreFactory">
+                        <bean class="org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory">
+                            <property name="sessionFactoryBean" value = "simpleSessionFactory1"/>
+                        </bean>
+                    </property>
+                </bean>
+            </list>
+        </property>
+
+        <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
+        <property name="discoverySpi">
+            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+                <property name="ipFinder">
+                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
+                        <property name="addresses">
+                            <list>
+                                <value>127.0.0.1:47500..47509</value>
+                            </list>
+                        </property>
+                    </bean>
+                </property>
+            </bean>
+        </property>
+    </bean>
+</beans>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheConfigurationSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheConfigurationSelfTest.java b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheConfigurationSelfTest.java
new file mode 100644
index 0000000..cb179c4
--- /dev/null
+++ b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheConfigurationSelfTest.java
@@ -0,0 +1,409 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import javax.cache.Cache;
+import javax.persistence.Cacheable;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+import org.hibernate.cache.spi.access.AccessType;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.service.ServiceRegistryBuilder;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.DFLT_ACCESS_TYPE_PROPERTY;
+import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.DFLT_CACHE_NAME_PROPERTY;
+import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.IGNITE_INSTANCE_NAME_PROPERTY;
+import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.REGION_CACHE_PROPERTY;
+import static org.hibernate.cfg.AvailableSettings.CACHE_REGION_FACTORY;
+import static org.hibernate.cfg.AvailableSettings.GENERATE_STATISTICS;
+import static org.hibernate.cfg.AvailableSettings.HBM2DDL_AUTO;
+import static org.hibernate.cfg.AvailableSettings.RELEASE_CONNECTIONS;
+import static org.hibernate.cfg.AvailableSettings.USE_QUERY_CACHE;
+import static org.hibernate.cfg.AvailableSettings.USE_SECOND_LEVEL_CACHE;
+
+/**
+ * Tests Hibernate L2 cache configuration.
+ */
+public class HibernateL2CacheConfigurationSelfTest extends GridCommonAbstractTest {
+    /** */
+    public static final String ENTITY1_NAME = Entity1.class.getName();
+
+    /** */
+    public static final String ENTITY2_NAME = Entity2.class.getName();
+
+    /** */
+    public static final String ENTITY3_NAME = Entity3.class.getName();
+
+    /** */
+    public static final String ENTITY4_NAME = Entity4.class.getName();
+
+    /** */
+    public static final String TIMESTAMP_CACHE = "org.hibernate.cache.spi.UpdateTimestampsCache";
+
+    /** */
+    public static final String QUERY_CACHE = "org.hibernate.cache.internal.StandardQueryCache";
+
+    /** */
+    public static final String CONNECTION_URL = "jdbc:h2:mem:example;DB_CLOSE_DELAY=-1";
+
+    /** If {@code true} then sets default cache in configuration. */
+    private boolean dfltCache;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrid(0);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        for (IgniteCacheProxy<?, ?> cache : ((IgniteKernal)grid(0)).caches())
+            cache.clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
+
+        discoSpi.setIpFinder(new TcpDiscoveryVmIpFinder(true));
+
+        cfg.setDiscoverySpi(discoSpi);
+
+        cfg.setCacheConfiguration(cacheConfiguration(ENTITY3_NAME), cacheConfiguration(ENTITY4_NAME),
+            cacheConfiguration("cache1"), cacheConfiguration("cache2"), cacheConfiguration("cache3"),
+            cacheConfiguration(TIMESTAMP_CACHE), cacheConfiguration(QUERY_CACHE));
+
+        return cfg;
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @return Cache configuration.
+     */
+    private CacheConfiguration cacheConfiguration(String cacheName) {
+        CacheConfiguration cfg = new CacheConfiguration();
+
+        cfg.setName(cacheName);
+
+        cfg.setCacheMode(PARTITIONED);
+
+        cfg.setAtomicityMode(ATOMIC);
+
+        return cfg;
+    }
+
+    /**
+     * @param igniteInstanceName Ignite instance name.
+     * @return Hibernate configuration.
+     */
+    protected Configuration hibernateConfiguration(String igniteInstanceName) {
+        Configuration cfg = new Configuration();
+
+        cfg.addAnnotatedClass(Entity1.class);
+        cfg.addAnnotatedClass(Entity2.class);
+        cfg.addAnnotatedClass(Entity3.class);
+        cfg.addAnnotatedClass(Entity4.class);
+
+        cfg.setProperty(DFLT_ACCESS_TYPE_PROPERTY, AccessType.NONSTRICT_READ_WRITE.name());
+
+        cfg.setProperty(HBM2DDL_AUTO, "create");
+
+        cfg.setProperty(GENERATE_STATISTICS, "true");
+
+        cfg.setProperty(USE_SECOND_LEVEL_CACHE, "true");
+
+        cfg.setProperty(USE_QUERY_CACHE, "true");
+
+        cfg.setProperty(CACHE_REGION_FACTORY, HibernateRegionFactory.class.getName());
+
+        cfg.setProperty(RELEASE_CONNECTIONS, "on_close");
+
+        cfg.setProperty(IGNITE_INSTANCE_NAME_PROPERTY, igniteInstanceName);
+
+        cfg.setProperty(REGION_CACHE_PROPERTY + ENTITY1_NAME, "cache1");
+        cfg.setProperty(REGION_CACHE_PROPERTY + ENTITY2_NAME, "cache2");
+        cfg.setProperty(REGION_CACHE_PROPERTY + TIMESTAMP_CACHE, TIMESTAMP_CACHE);
+        cfg.setProperty(REGION_CACHE_PROPERTY + QUERY_CACHE, QUERY_CACHE);
+
+        if (dfltCache)
+            cfg.setProperty(DFLT_CACHE_NAME_PROPERTY, "cache3");
+
+        return cfg;
+    }
+
+    /**
+     * Tests property {@link HibernateAccessStrategyFactory#REGION_CACHE_PROPERTY}.
+     */
+    public void testPerRegionCacheProperty() {
+        testCacheUsage(1, 1, 0, 1, 1);
+    }
+
+    /**
+     * Tests property {@link HibernateAccessStrategyFactory#DFLT_CACHE_NAME_PROPERTY}.
+     */
+    public void testDefaultCache() {
+        dfltCache = true;
+
+        testCacheUsage(1, 1, 2, 0, 0);
+    }
+
+    /**
+     * @param expCache1 Expected size of cache with name 'cache1'.
+     * @param expCache2 Expected size of cache with name 'cache2'.
+     * @param expCache3 Expected size of cache with name 'cache3'.
+     * @param expCacheE3 Expected size of cache with name {@link #ENTITY3_NAME}.
+     * @param expCacheE4 Expected size of cache with name {@link #ENTITY4_NAME}.
+     */
+    @SuppressWarnings("unchecked")
+    private void testCacheUsage(int expCache1, int expCache2, int expCache3, int expCacheE3, int expCacheE4) {
+        SessionFactory sesFactory = startHibernate(getTestIgniteInstanceName(0));
+
+        try {
+            Session ses = sesFactory.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                ses.save(new Entity1());
+                ses.save(new Entity2());
+                ses.save(new Entity3());
+                ses.save(new Entity4());
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            ses = sesFactory.openSession();
+
+            try {
+                List<Entity1> list1 = ses.createCriteria(ENTITY1_NAME).list();
+
+                assertEquals(1, list1.size());
+
+                for (Entity1 e : list1) {
+                    ses.load(ENTITY1_NAME, e.getId());
+                    assertNotNull(e.getId());
+                }
+
+                List<Entity2> list2 = ses.createCriteria(ENTITY2_NAME).list();
+
+                assertEquals(1, list2.size());
+
+                for (Entity2 e : list2)
+                    assertNotNull(e.getId());
+
+                List<Entity3> list3 = ses.createCriteria(ENTITY3_NAME).list();
+
+                assertEquals(1, list3.size());
+
+                for (Entity3 e : list3)
+                    assertNotNull(e.getId());
+
+                List<Entity4> list4 = ses.createCriteria(ENTITY4_NAME).list();
+
+                assertEquals(1, list4.size());
+
+                for (Entity4 e : list4)
+                    assertNotNull(e.getId());
+            }
+            finally {
+                ses.close();
+            }
+
+            IgniteCache<Object, Object> cache1 = grid(0).cache("cache1");
+            IgniteCache<Object, Object> cache2 = grid(0).cache("cache2");
+            IgniteCache<Object, Object> cache3 = grid(0).cache("cache3");
+            IgniteCache<Object, Object> cacheE3 = grid(0).cache(ENTITY3_NAME);
+            IgniteCache<Object, Object> cacheE4 = grid(0).cache(ENTITY4_NAME);
+
+            assertEquals("Unexpected entries: " + toSet(cache1.iterator()), expCache1, cache1.size());
+            assertEquals("Unexpected entries: " + toSet(cache2.iterator()), expCache2, cache2.size());
+            assertEquals("Unexpected entries: " + toSet(cache3.iterator()), expCache3, cache3.size());
+            assertEquals("Unexpected entries: " + toSet(cacheE3.iterator()), expCacheE3, cacheE3.size());
+            assertEquals("Unexpected entries: " + toSet(cacheE4.iterator()), expCacheE4, cacheE4.size());
+        }
+        finally {
+            sesFactory.close();
+        }
+    }
+
+    /**
+     *
+     */
+    private <K, V> Set<Cache.Entry<K, V>> toSet(Iterator<Cache.Entry<K, V>> iter){
+        Set<Cache.Entry<K, V>> set = new HashSet<>();
+
+        while (iter.hasNext())
+            set.add(iter.next());
+
+        return set;
+    }
+
+    /**
+     * @param igniteInstanceName Name of the grid providing caches.
+     * @return Session factory.
+     */
+    private SessionFactory startHibernate(String igniteInstanceName) {
+        Configuration cfg = hibernateConfiguration(igniteInstanceName);
+
+        ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
+
+        builder.applySetting("hibernate.connection.url", CONNECTION_URL);
+        builder.applySetting("hibernate.show_sql", false);
+
+        return cfg.buildSessionFactory(builder.buildServiceRegistry());
+    }
+
+    /**
+     * Test Hibernate entity1.
+     */
+    @javax.persistence.Entity
+    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
+    @Cacheable
+    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+    public static class Entity1 {
+        /** */
+        private int id;
+
+        /**
+         * @return ID.
+         */
+        @Id
+        @GeneratedValue
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(int id) {
+            this.id = id;
+        }
+    }
+
+    /**
+     * Test Hibernate entity2.
+     */
+    @javax.persistence.Entity
+    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
+    @Cacheable
+    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+    public static class Entity2 {
+        /** */
+        private int id;
+
+        /**
+         * @return ID.
+         */
+        @Id
+        @GeneratedValue
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(int id) {
+            this.id = id;
+        }
+    }
+
+    /**
+     * Test Hibernate entity3.
+     */
+    @javax.persistence.Entity
+    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
+    @Cacheable
+    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+    public static class Entity3 {
+        /** */
+        private int id;
+
+        /**
+         * @return ID.
+         */
+        @Id
+        @GeneratedValue
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(int id) {
+            this.id = id;
+        }
+    }
+
+    /**
+     * Test Hibernate entity4.
+     */
+    @javax.persistence.Entity
+    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
+    @Cacheable
+    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+    public static class Entity4 {
+        /** */
+        private int id;
+
+        /**
+         * @return ID.
+         */
+        @Id
+        @GeneratedValue
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(int id) {
+            this.id = id;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheMultiJvmTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheMultiJvmTest.java b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheMultiJvmTest.java
new file mode 100644
index 0000000..5160220
--- /dev/null
+++ b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheMultiJvmTest.java
@@ -0,0 +1,440 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import java.util.Map;
+import javax.persistence.Cacheable;
+import javax.persistence.Id;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCompute;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.resources.IgniteInstanceResource;
+import org.apache.ignite.resources.LoggerResource;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.service.ServiceRegistryBuilder;
+
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.DFLT_CACHE_NAME_PROPERTY;
+import static org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest.CONNECTION_URL;
+import static org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest.hibernateProperties;
+import static org.hibernate.cache.spi.access.AccessType.NONSTRICT_READ_WRITE;
+
+/**
+ *
+ */
+public class HibernateL2CacheMultiJvmTest extends GridCommonAbstractTest {
+    /** */
+    private static final String CACHE_NAME = "hibernateCache";
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        if (!getTestIgniteInstanceName(0).equals(igniteInstanceName))
+            cfg.setClientMode(true);
+
+        CacheConfiguration ccfg = new CacheConfiguration();
+
+        ccfg.setName(CACHE_NAME);
+        ccfg.setWriteSynchronizationMode(FULL_SYNC);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        cfg.setPeerClassLoadingEnabled(false);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean isMultiJvm() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        startGrid(0);
+
+        startGrid(1);
+        startGrid(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+
+        super.afterTestsStopped();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testL2Cache() throws Exception {
+        Ignite srv = ignite(0);
+
+        {
+            IgniteCompute client1Compute =
+                srv.compute(srv.cluster().forNodeId(ignite(1).cluster().localNode().id()));
+
+            client1Compute.run(new HibernateInsertRunnable());
+        }
+
+        {
+            IgniteCompute client2Compute =
+                srv.compute(srv.cluster().forNodeId(ignite(2).cluster().localNode().id()));
+
+            client2Compute.run(new HibernateLoadRunnable());
+        }
+
+        {
+            IgniteCompute srvCompute = srv.compute(srv.cluster().forLocal());
+
+            srvCompute.run(new HibernateLoadRunnable());
+        }
+    }
+
+    /**
+     *
+     */
+    private static class HibernateInsertRunnable extends HibernateBaseRunnable {
+        /** {@inheritDoc} */
+        @Override public void run() {
+            SessionFactory sesFactory = startHibernate(ignite.name());
+
+            Session ses = sesFactory.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                for (int i = 0; i < 1; i++) {
+                    {
+                        Entity1 e = new Entity1();
+                        e.setId(i);
+                        e.setName("name-" + i);
+
+                        ses.save(e);
+                    }
+
+                    {
+                        Entity2 e = new Entity2();
+                        e.setId(String.valueOf(i));
+                        e.setName("name-" + i);
+
+                        ses.save(e);
+                    }
+
+                    {
+                        Entity3 e = new Entity3();
+                        e.setId(i);
+                        e.setName("name-" + i);
+
+                        ses.save(e);
+                    }
+                }
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+        }
+    }
+
+    /**
+     *
+     */
+    private static class HibernateLoadRunnable extends HibernateBaseRunnable {
+        /** {@inheritDoc} */
+        @Override public void run() {
+            SessionFactory sesFactory = startHibernate(ignite.name());
+
+            Session ses = sesFactory.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                for (int i = 0; i < 1; i++) {
+                    {
+                        Entity1 e = (Entity1)ses.load(Entity1.class, i);
+
+                        log.info("Found: " + e.getName());
+                    }
+                    {
+                        Entity2 e = (Entity2)ses.load(Entity2.class, String.valueOf(i));
+
+                        log.info("Found: " + e.getName());
+                    }
+                    {
+                        Entity3 e = (Entity3)ses.load(Entity3.class, (double)i);
+
+                        log.info("Found: " + e.getName());
+                    }
+                }
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+        }
+    }
+
+    /**
+     *
+     */
+    private abstract static class HibernateBaseRunnable implements IgniteRunnable {
+        /** */
+        @IgniteInstanceResource
+        protected Ignite ignite;
+
+        /** */
+        @LoggerResource
+        IgniteLogger log;
+
+        /**
+         * @param igniteInstanceName Name of the grid providing caches.
+         * @return Session factory.
+         */
+        SessionFactory startHibernate(String igniteInstanceName) {
+            log.info("Start hibernate on node: " + igniteInstanceName);
+
+            Configuration cfg = hibernateConfiguration(igniteInstanceName);
+
+            ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
+
+            builder.applySetting("hibernate.connection.url", CONNECTION_URL);
+
+            return cfg.buildSessionFactory(builder.buildServiceRegistry());
+        }
+
+        /**
+         * @param nodeName Ignite instance name.
+         * @return Hibernate configuration.
+         */
+        private Configuration hibernateConfiguration(String nodeName) {
+            Configuration cfg = new Configuration();
+
+            cfg.addAnnotatedClass(Entity1.class);
+            cfg.addAnnotatedClass(Entity2.class);
+            cfg.addAnnotatedClass(Entity3.class);
+
+            for (Map.Entry<String, String> e : hibernateProperties(nodeName, NONSTRICT_READ_WRITE.name()).entrySet())
+                cfg.setProperty(e.getKey(), e.getValue());
+
+            cfg.setProperty(DFLT_CACHE_NAME_PROPERTY, CACHE_NAME);
+
+            return cfg;
+        }
+    }
+
+    /**
+     * Test Hibernate entity1.
+     */
+    @javax.persistence.Entity
+    @Cacheable
+    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+    public static class Entity1 {
+        /** */
+        @Id
+        private int id;
+
+        /** */
+        private String name;
+
+        /**
+         * @return ID.
+         */
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(int id) {
+            this.id = id;
+        }
+
+        /**
+         * @return Name.
+         */
+        public String getName() {
+            return name;
+        }
+
+        /**
+         * @param name Name.
+         */
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            Entity1 entity1 = (Entity1)o;
+
+            return id == entity1.id;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return id;
+        }
+    }
+
+    /**
+     * Test Hibernate entity1.
+     */
+    @javax.persistence.Entity
+    @Cacheable
+    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+    public static class Entity2 {
+        /** */
+        @Id
+        private String id;
+
+        /** */
+        private String name;
+
+        /**
+         * @return ID.
+         */
+        public String getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(String id) {
+            this.id = id;
+        }
+
+        /**
+         * @return Name.
+         */
+        public String getName() {
+            return name;
+        }
+
+        /**
+         * @param name Name.
+         */
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            Entity2 entity2 = (Entity2)o;
+
+            return id.equals(entity2.id);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return id.hashCode();
+        }
+    }
+
+    /**
+     * Test Hibernate entity1.
+     */
+    @javax.persistence.Entity
+    @Cacheable
+    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
+    public static class Entity3 {
+        /** */
+        @Id
+        private double id;
+
+        /** */
+        private String name;
+
+        /**
+         * @return ID.
+         */
+        public double getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(double id) {
+            this.id = id;
+        }
+
+        /**
+         * @return Name.
+         */
+        public String getName() {
+            return name;
+        }
+
+        /**
+         * @param name Name.
+         */
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            Entity3 entity3 = (Entity3)o;
+
+            return Double.compare(entity3.id, id) == 0;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            long temp = Double.doubleToLongBits(id);
+            return (int)(temp ^ (temp >>> 32));
+        }
+    }
+}


[03/16] ignite git commit: ignite-1794 Refactored hibernate modules, switched to hibernate 5.1

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java
deleted file mode 100644
index c87f08f..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStore.java
+++ /dev/null
@@ -1,542 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.store.hibernate;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Map;
-import java.util.Properties;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.atomic.AtomicBoolean;
-import javax.cache.integration.CacheLoaderException;
-import javax.cache.integration.CacheWriterException;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.cache.store.CacheStore;
-import org.apache.ignite.cache.store.CacheStoreAdapter;
-import org.apache.ignite.cache.store.CacheStoreSession;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.internal.IgniteInterruptedCheckedException;
-import org.apache.ignite.internal.util.tostring.GridToStringExclude;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.marshaller.jdk.JdkMarshaller;
-import org.apache.ignite.resources.CacheStoreSessionResource;
-import org.apache.ignite.resources.IgniteInstanceResource;
-import org.apache.ignite.resources.LoggerResource;
-import org.apache.ignite.transactions.Transaction;
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.SharedSessionContract;
-import org.hibernate.cfg.Configuration;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * {@link CacheStore} implementation backed by Hibernate. This implementation
- * stores objects in underlying database in {@code BLOB} format.
- * <h2 class="header">Configuration</h2>
- * Either {@link #setSessionFactory(SessionFactory)} or
- * {@link #setHibernateConfigurationPath(String)} or
- * {@link #setHibernateProperties(Properties)} should be set.
- * <p>
- * If session factory is provided it should contain
- * {@link CacheHibernateBlobStoreEntry} persistent class (via provided
- * mapping file {@code GridCacheHibernateStoreEntry.hbm.xml} or by
- * adding {@link CacheHibernateBlobStoreEntry} to annotated classes
- * of session factory.
- * <p>
- * Path to hibernate configuration may be either an URL or a file path or
- * a classpath resource. This configuration file should include provided
- * mapping {@code GridCacheHibernateStoreEntry.hbm.xml} or include annotated
- * class {@link CacheHibernateBlobStoreEntry}.
- * <p>
- * If hibernate properties are provided, mapping
- * {@code GridCacheHibernateStoreEntry.hbm.xml} is included automatically.
- * <p>
- * Use {@link CacheHibernateBlobStoreFactory} factory to pass {@link CacheHibernateBlobStore} to {@link CacheConfiguration}.
- */
-public class CacheHibernateBlobStore<K, V> extends CacheStoreAdapter<K, V> {
-    /**
-     * Default connection URL
-     * (value is <tt>jdbc:h2:mem:hibernateCacheStore;DB_CLOSE_DELAY=-1;DEFAULT_LOCK_TIMEOUT=5000</tt>).
-     */
-    public static final String DFLT_CONN_URL = "jdbc:h2:mem:hibernateCacheStore;DB_CLOSE_DELAY=-1;" +
-        "DEFAULT_LOCK_TIMEOUT=5000";
-
-    /** Default show SQL property value (value is <tt>true</tt>). */
-    public static final String DFLT_SHOW_SQL = "true";
-
-    /** Default <tt>hibernate.hbm2ddl.auto</tt> property value (value is <tt>true</tt>). */
-    public static final String DFLT_HBM2DDL_AUTO = "update";
-
-    /** Session attribute name. */
-    private static final String ATTR_SES = "HIBERNATE_STORE_SESSION";
-
-    /** Name of Hibarname mapping resource. */
-    private static final String MAPPING_RESOURCE =
-            "org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml";
-
-    /** Marshaller. */
-    private static final Marshaller marsh = new JdkMarshaller();
-
-    /** Init guard. */
-    @GridToStringExclude
-    private final AtomicBoolean initGuard = new AtomicBoolean();
-
-    /** Init latch. */
-    @GridToStringExclude
-    private final CountDownLatch initLatch = new CountDownLatch(1);
-
-    /** Hibernate properties. */
-    @GridToStringExclude
-    private Properties hibernateProps;
-
-    /** Session factory. */
-    @GridToStringExclude
-    private SessionFactory sesFactory;
-
-    /** Path to hibernate configuration file. */
-    private String hibernateCfgPath;
-
-    /** Log. */
-    @LoggerResource
-    private IgniteLogger log;
-
-    /** Auto-injected store session. */
-    @CacheStoreSessionResource
-    private CacheStoreSession ses;
-
-    /** Ignite instance. */
-    @IgniteInstanceResource
-    private Ignite ignite;
-
-    /** {@inheritDoc} */
-    @SuppressWarnings({"unchecked", "RedundantTypeArguments"})
-    @Override public V load(K key) {
-        init();
-
-        Transaction tx = transaction();
-
-        if (log.isDebugEnabled())
-            log.debug("Store load [key=" + key + ", tx=" + tx + ']');
-
-        Session ses = session(tx);
-
-        try {
-            CacheHibernateBlobStoreEntry entry = (CacheHibernateBlobStoreEntry)
-                ses.get(CacheHibernateBlobStoreEntry.class, toBytes(key));
-
-            if (entry == null)
-                return null;
-
-            return fromBytes(entry.getValue());
-        }
-        catch (IgniteCheckedException | HibernateException e) {
-            rollback(ses, tx);
-
-            throw new CacheLoaderException("Failed to load value from cache store with key: " + key, e);
-        }
-        finally {
-            end(ses, tx);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void write(javax.cache.Cache.Entry<? extends K, ? extends V> entry) {
-        init();
-
-        Transaction tx = transaction();
-
-        K key = entry.getKey();
-        V val = entry.getValue();
-
-        if (log.isDebugEnabled())
-            log.debug("Store put [key=" + key + ", val=" + val + ", tx=" + tx + ']');
-
-        if (val == null) {
-            delete(key);
-
-            return;
-        }
-
-        Session ses = session(tx);
-
-        try {
-            CacheHibernateBlobStoreEntry entry0 = new CacheHibernateBlobStoreEntry(toBytes(key), toBytes(val));
-
-            ses.saveOrUpdate(entry0);
-        }
-        catch (IgniteCheckedException | HibernateException e) {
-            rollback(ses, tx);
-
-            throw new CacheWriterException("Failed to put value to cache store [key=" + key + ", val" + val + "]", e);
-        }
-        finally {
-            end(ses, tx);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings({"JpaQueryApiInspection", "JpaQlInspection"})
-    @Override public void delete(Object key) {
-        init();
-
-        Transaction tx = transaction();
-
-        if (log.isDebugEnabled())
-            log.debug("Store remove [key=" + key + ", tx=" + tx + ']');
-
-        Session ses = session(tx);
-
-        try {
-            Object obj = ses.get(CacheHibernateBlobStoreEntry.class, toBytes(key));
-
-            if (obj != null)
-                ses.delete(obj);
-        }
-        catch (IgniteCheckedException | HibernateException e) {
-            rollback(ses, tx);
-
-            throw new CacheWriterException("Failed to remove value from cache store with key: " + key, e);
-        }
-        finally {
-            end(ses, tx);
-        }
-    }
-
-    /**
-     * Rolls back hibernate session.
-     *
-     * @param ses Hibernate session.
-     * @param tx Cache ongoing transaction.
-     */
-    private void rollback(SharedSessionContract ses, Transaction tx) {
-        // Rollback only if there is no cache transaction,
-        // otherwise sessionEnd() will do all required work.
-        if (tx == null) {
-            org.hibernate.Transaction hTx = ses.getTransaction();
-
-            if (hTx != null && hTx.isActive())
-                hTx.rollback();
-        }
-    }
-
-    /**
-     * Ends hibernate session.
-     *
-     * @param ses Hibernate session.
-     * @param tx Cache ongoing transaction.
-     */
-    private void end(Session ses, Transaction tx) {
-        // Commit only if there is no cache transaction,
-        // otherwise sessionEnd() will do all required work.
-        if (tx == null) {
-            org.hibernate.Transaction hTx = ses.getTransaction();
-
-            if (hTx != null && hTx.isActive())
-                hTx.commit();
-
-            ses.close();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void sessionEnd(boolean commit) {
-        init();
-
-        Transaction tx = transaction();
-
-        Map<String, Session> props = session().properties();
-
-        Session ses = props.remove(ATTR_SES);
-
-        if (ses != null) {
-            org.hibernate.Transaction hTx = ses.getTransaction();
-
-            if (hTx != null) {
-                try {
-                    if (commit) {
-                        ses.flush();
-
-                        hTx.commit();
-                    }
-                    else
-                        hTx.rollback();
-
-                    if (log.isDebugEnabled())
-                        log.debug("Transaction ended [xid=" + tx.xid() + ", commit=" + commit + ']');
-                }
-                catch (HibernateException e) {
-                    throw new CacheWriterException("Failed to end transaction [xid=" + tx.xid() +
-                        ", commit=" + commit + ']', e);
-                }
-                finally {
-                    ses.close();
-                }
-            }
-        }
-    }
-
-    /**
-     * Gets Hibernate session.
-     *
-     * @param tx Cache transaction.
-     * @return Session.
-     */
-    Session session(@Nullable Transaction tx) {
-        Session ses;
-
-        if (tx != null) {
-            Map<String, Session> props = session().properties();
-
-            ses = props.get(ATTR_SES);
-
-            if (ses == null) {
-                ses = sesFactory.openSession();
-
-                ses.beginTransaction();
-
-                // Store session in transaction metadata, so it can be accessed
-                // for other operations on the same transaction.
-                props.put(ATTR_SES, ses);
-
-                if (log.isDebugEnabled())
-                    log.debug("Hibernate session open [ses=" + ses + ", tx=" + tx.xid() + "]");
-            }
-        }
-        else {
-            ses = sesFactory.openSession();
-
-            ses.beginTransaction();
-        }
-
-        return ses;
-    }
-
-    /**
-     * Sets session factory.
-     *
-     * @param sesFactory Session factory.
-     */
-    public void setSessionFactory(SessionFactory sesFactory) {
-        this.sesFactory = sesFactory;
-    }
-
-    /**
-     * Sets hibernate configuration path.
-     * <p>
-     * This may be either URL or file path or classpath resource.
-     *
-     * @param hibernateCfgPath URL or file path or classpath resource
-     *      pointing to hibernate configuration XML file.
-     */
-    public void setHibernateConfigurationPath(String hibernateCfgPath) {
-        this.hibernateCfgPath = hibernateCfgPath;
-    }
-
-    /**
-     * Sets Hibernate properties.
-     *
-     * @param hibernateProps Hibernate properties.
-     */
-    public void setHibernateProperties(Properties hibernateProps) {
-        this.hibernateProps = hibernateProps;
-    }
-
-    /**
-     * Initializes store.
-     *
-     * @throws IgniteException If failed to initialize.
-     */
-    private void init() throws IgniteException {
-        if (initGuard.compareAndSet(false, true)) {
-            if (log.isDebugEnabled())
-                log.debug("Initializing cache store.");
-
-            try {
-                if (sesFactory != null)
-                    // Session factory has been provided - nothing to do.
-                    return;
-
-                if (!F.isEmpty(hibernateCfgPath)) {
-                    try {
-                        URL url = new URL(hibernateCfgPath);
-
-                        sesFactory = new Configuration().configure(url).buildSessionFactory();
-
-                        if (log.isDebugEnabled())
-                            log.debug("Configured session factory using URL: " + url);
-
-                        // Session factory has been successfully initialized.
-                        return;
-                    }
-                    catch (MalformedURLException e) {
-                        if (log.isDebugEnabled())
-                            log.debug("Caught malformed URL exception: " + e.getMessage());
-                    }
-
-                    // Provided path is not a valid URL. File?
-                    File cfgFile = new File(hibernateCfgPath);
-
-                    if (cfgFile.exists()) {
-                        sesFactory = new Configuration().configure(cfgFile).buildSessionFactory();
-
-                        if (log.isDebugEnabled())
-                            log.debug("Configured session factory using file: " + hibernateCfgPath);
-
-                        // Session factory has been successfully initialized.
-                        return;
-                    }
-
-                    // Provided path is not a file. Classpath resource?
-                    sesFactory = new Configuration().configure(hibernateCfgPath).buildSessionFactory();
-
-                    if (log.isDebugEnabled())
-                        log.debug("Configured session factory using classpath resource: " + hibernateCfgPath);
-                }
-                else {
-                    if (hibernateProps == null) {
-                        U.warn(log, "No Hibernate configuration has been provided for store (will use default).");
-
-                        hibernateProps = new Properties();
-
-                        hibernateProps.setProperty("hibernate.connection.url", DFLT_CONN_URL);
-                        hibernateProps.setProperty("hibernate.show_sql", DFLT_SHOW_SQL);
-                        hibernateProps.setProperty("hibernate.hbm2ddl.auto", DFLT_HBM2DDL_AUTO);
-                    }
-
-                    Configuration cfg = new Configuration();
-
-                    cfg.setProperties(hibernateProps);
-
-                    assert resourceAvailable(MAPPING_RESOURCE) : MAPPING_RESOURCE;
-
-                    cfg.addResource(MAPPING_RESOURCE);
-
-                    sesFactory = cfg.buildSessionFactory();
-
-                    if (log.isDebugEnabled())
-                        log.debug("Configured session factory using properties: " + hibernateProps);
-                }
-            }
-            catch (HibernateException e) {
-                throw new IgniteException("Failed to initialize store.", e);
-            }
-            finally {
-                initLatch.countDown();
-            }
-        }
-        else if (initLatch.getCount() > 0) {
-            try {
-                U.await(initLatch);
-            }
-            catch (IgniteInterruptedCheckedException e) {
-                throw new IgniteException(e);
-            }
-        }
-
-        if (sesFactory == null)
-            throw new IgniteException("Cache store was not properly initialized.");
-    }
-
-    /**
-     * Checks availability of a classpath resource.
-     *
-     * @param name Resource name.
-     * @return {@code true} if resource is available and ready for read, {@code false} otherwise.
-     */
-    private boolean resourceAvailable(String name) {
-        InputStream cfgStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
-
-        if (cfgStream == null) {
-            log.error("Classpath resource not found: " + name);
-
-            return false;
-        }
-
-        try {
-            // Read a single byte to force actual content access by JVM.
-            cfgStream.read();
-
-            return true;
-        }
-        catch (IOException e) {
-            log.error("Failed to read classpath resource: " + name, e);
-
-            return false;
-        }
-        finally {
-            U.close(cfgStream, log);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(CacheHibernateBlobStore.class, this);
-    }
-
-    /**
-     * Serialize object to byte array using marshaller.
-     *
-     * @param obj Object to convert to byte array.
-     * @return Byte array.
-     * @throws IgniteCheckedException If failed to convert.
-     */
-    protected byte[] toBytes(Object obj) throws IgniteCheckedException {
-        return U.marshal(marsh, obj);
-    }
-
-    /**
-     * Deserialize object from byte array using marshaller.
-     *
-     * @param bytes Bytes to deserialize.
-     * @param <X> Result object type.
-     * @return Deserialized object.
-     * @throws IgniteCheckedException If failed.
-     */
-    protected <X> X fromBytes(byte[] bytes) throws IgniteCheckedException {
-        if (bytes == null || bytes.length == 0)
-            return null;
-
-        return U.unmarshal(marsh, bytes, getClass().getClassLoader());
-    }
-
-    /**
-     * @return Current transaction.
-     */
-    @Nullable private Transaction transaction() {
-        CacheStoreSession ses = session();
-
-        return ses != null ? ses.transaction() : null;
-    }
-
-    /**
-     * @return Store session.
-     */
-    private CacheStoreSession session() {
-        return ses;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml b/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml
deleted file mode 100644
index 5b0be43..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one or more
-  contributor license agreements.  See the NOTICE file distributed with
-  this work for additional information regarding copyright ownership.
-  The ASF licenses this file to You under the Apache License, Version 2.0
-  (the "License"); you may not use this file except in compliance with
-  the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-
-
-<!DOCTYPE hibernate-mapping PUBLIC
-        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
-        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
-
-<hibernate-mapping package="org.apache.ignite.examples.datagrid.store" default-access="field">
-    <class name="org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreEntry" table="ENTRIES">
-        <id name="key"/>
-
-        <property name="val"/>
-    </class>
-</hibernate-mapping>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.java
deleted file mode 100644
index d40c5ef..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.store.hibernate;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
-
-/**
- * Entry that is used by {@link CacheHibernateBlobStore} implementation.
- * <p>
- * Note that this is a reference implementation for tests only.
- * When running on production systems use concrete key-value types to
- * get better performance.
- */
-@Entity
-@Table(name = "ENTRIES")
-public class CacheHibernateBlobStoreEntry {
-    /** Key (use concrete key type in production). */
-    @Id
-    @Column(length = 65535)
-    private byte[] key;
-
-    /** Value (use concrete value type in production). */
-    @Column(length = 65535)
-    private byte[] val;
-
-    /**
-     * Constructor.
-     */
-    CacheHibernateBlobStoreEntry() {
-        // No-op.
-    }
-
-    /**
-     * Constructor.
-     *
-     * @param key Key.
-     * @param val Value.
-     */
-    CacheHibernateBlobStoreEntry(byte[] key, byte[] val) {
-        this.key = key;
-        this.val = val;
-    }
-
-    /**
-     * @return Key.
-     */
-    public byte[] getKey() {
-        return key;
-    }
-
-    /**
-     * @param key Key.
-     */
-    public void setKey(byte[] key) {
-        this.key = key;
-    }
-
-    /**
-     * @return Value.
-     */
-    public byte[] getValue() {
-        return val;
-    }
-
-    /**
-     * @param val Value.
-     */
-    public void setValue(byte[] val) {
-        this.val = val;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreFactory.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreFactory.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreFactory.java
deleted file mode 100644
index ea4df8a..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreFactory.java
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.store.hibernate;
-
-import java.util.Properties;
-import javax.cache.configuration.Factory;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.internal.IgniteComponentType;
-import org.apache.ignite.internal.util.spring.IgniteSpringHelper;
-import org.apache.ignite.internal.util.tostring.GridToStringExclude;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.resources.SpringApplicationContextResource;
-import org.hibernate.SessionFactory;
-
-/**
- * {@link Factory} implementation for {@link CacheHibernateBlobStore}.
- *
- * Use this factory to pass {@link CacheHibernateBlobStore} to {@link CacheConfiguration}.
- *
- * <h2 class="header">Java Example</h2>
- * In this example existing session factory is provided.
- * <pre name="code" class="java">
- *     ...
- *     CacheHibernateBlobStoreFactory&lt;String, String&gt; factory = new CacheHibernateBlobStoreFactory&lt;String, String&gt;();
- *
- *     factory.setSessionFactory(sesFactory);
- *     ...
- * </pre>
- *
- * <h2 class="header">Spring Example (using Spring ORM)</h2>
- * <pre name="code" class="xml">
- *   ...
- *   &lt;bean id=&quot;cache.hibernate.store.factory&quot;
- *       class=&quot;org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory&quot;&gt;
- *       &lt;property name=&quot;sessionFactory&quot;&gt;
- *           &lt;bean class=&quot;org.springframework.orm.hibernate3.LocalSessionFactoryBean&quot;&gt;
- *               &lt;property name=&quot;hibernateProperties&quot;&gt;
- *                   &lt;value&gt;
- *                       connection.url=jdbc:h2:mem:
- *                       show_sql=true
- *                       hbm2ddl.auto=true
- *                       hibernate.dialect=org.hibernate.dialect.H2Dialect
- *                   &lt;/value&gt;
- *               &lt;/property&gt;
- *               &lt;property name=&quot;mappingResources&quot;&gt;
- *                   &lt;list&gt;
- *                       &lt;value&gt;
- *                           org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreEntry.hbm.xml
- *                       &lt;/value&gt;
- *                   &lt;/list&gt;
- *               &lt;/property&gt;
- *           &lt;/bean&gt;
- *       &lt;/property&gt;
- *   &lt;/bean&gt;
- *   ...
- * </pre>
- *
- * <h2 class="header">Spring Example (using Spring ORM and persistent annotations)</h2>
- * <pre name="code" class="xml">
- *     ...
- *     &lt;bean id=&quot;cache.hibernate.store.factory1&quot;
- *         class=&quot;org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory&quot;&gt;
- *         &lt;property name=&quot;sessionFactory&quot;&gt;
- *             &lt;bean class=&quot;org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean&quot;&gt;
- *                 &lt;property name=&quot;hibernateProperties&quot;&gt;
- *                     &lt;value&gt;
- *                         connection.url=jdbc:h2:mem:
- *                         show_sql=true
- *                         hbm2ddl.auto=true
- *                         hibernate.dialect=org.hibernate.dialect.H2Dialect
- *                     &lt;/value&gt;
- *                 &lt;/property&gt;
- *                 &lt;property name=&quot;annotatedClasses&quot;&gt;
- *                     &lt;list&gt;
- *                         &lt;value&gt;
- *                             org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreEntry
- *                         &lt;/value&gt;
- *                     &lt;/list&gt;
- *                 &lt;/property&gt;
- *             &lt;/bean&gt;
- *         &lt;/property&gt;
- *     &lt;/bean&gt;
- *     ...
- * </pre>
- *
- * <h2 class="header">Spring Example</h2>
- * <pre name="code" class="xml">
- *     ...
- *     &lt;bean id=&quot;cache.hibernate.store.factory2&quot;
- *         class=&quot;org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory&quot;&gt;
- *         &lt;property name=&quot;hibernateProperties&quot;&gt;
- *             &lt;props&gt;
- *                 &lt;prop key=&quot;connection.url&quot;&gt;jdbc:h2:mem:&lt;/prop&gt;
- *                 &lt;prop key=&quot;hbm2ddl.auto&quot;&gt;update&lt;/prop&gt;
- *                 &lt;prop key=&quot;show_sql&quot;&gt;true&lt;/prop&gt;
- *             &lt;/props&gt;
- *         &lt;/property&gt;
- *     &lt;/bean&gt;
- *     ...
- * </pre>
- * <p>
- * <img src="http://ignite.apache.org/images/spring-small.png">
- * <br>
- * For information about Spring framework visit <a href="http://www.springframework.org/">www.springframework.org</a>
- */
-public class CacheHibernateBlobStoreFactory<K, V> implements Factory<CacheHibernateBlobStore<K, V>> {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** Session factory. */
-    @GridToStringExclude
-    private transient SessionFactory sesFactory;
-
-    /** Session factory bean name. */
-    private String sesFactoryBean;
-
-    /** Path to hibernate configuration file. */
-    private String hibernateCfgPath;
-
-    /** Hibernate properties. */
-    @GridToStringExclude
-    private Properties hibernateProps;
-
-    /** Application context. */
-    @SpringApplicationContextResource
-    private Object appContext;
-
-    /** {@inheritDoc} */
-    @Override public CacheHibernateBlobStore<K, V> create() {
-        CacheHibernateBlobStore<K, V> store = new CacheHibernateBlobStore<>();
-
-        store.setHibernateConfigurationPath(hibernateCfgPath);
-        store.setHibernateProperties(hibernateProps);
-
-        if (sesFactory != null)
-            store.setSessionFactory(sesFactory);
-        else if (sesFactoryBean != null) {
-            if (appContext == null)
-                throw new IgniteException("Spring application context resource is not injected.");
-
-            IgniteSpringHelper spring;
-
-            try {
-                spring = IgniteComponentType.SPRING.create(false);
-
-                SessionFactory sesFac = spring.loadBeanFromAppContext(appContext, sesFactoryBean);
-
-                store.setSessionFactory(sesFac);
-            }
-            catch (IgniteCheckedException e) {
-                throw new IgniteException("Failed to load bean in application context [beanName=" + sesFactoryBean +
-                        ", igniteConfig=" + appContext + ']');
-            }
-        }
-
-        return store;
-    }
-
-    /**
-     * Sets session factory.
-     *
-     * @param sesFactory Session factory.
-     * @return {@code This} for chaining.
-     * @see CacheHibernateBlobStore#setSessionFactory(SessionFactory)
-     */
-    public CacheHibernateBlobStoreFactory<K, V> setSessionFactory(SessionFactory sesFactory) {
-        this.sesFactory = sesFactory;
-
-        return this;
-    }
-
-    /**
-     * Sets name of the data source bean.
-     *
-     * @param sesFactory Session factory bean name.
-     * @return {@code This} for chaining.
-     * @see CacheHibernateBlobStore#setSessionFactory(SessionFactory)
-     */
-    public CacheHibernateBlobStoreFactory<K, V> setSessionFactoryBean(String sesFactory) {
-        this.sesFactoryBean = sesFactory;
-
-        return this;
-    }
-
-    /**
-     * Sets hibernate configuration path.
-     * <p>
-     * This may be either URL or file path or classpath resource.
-     *
-     * @param hibernateCfgPath URL or file path or classpath resource
-     *      pointing to hibernate configuration XML file.
-     * @return {@code This} for chaining.
-     * @see CacheHibernateBlobStore#setHibernateConfigurationPath(String)
-     */
-    public CacheHibernateBlobStoreFactory<K, V> setHibernateConfigurationPath(String hibernateCfgPath) {
-        this.hibernateCfgPath = hibernateCfgPath;
-
-        return this;
-    }
-
-    /**
-     * Sets Hibernate properties.
-     *
-     * @param hibernateProps Hibernate properties.
-     * @return {@code This} for chaining.
-     * @see CacheHibernateBlobStore#setHibernateProperties(Properties)
-     */
-    public CacheHibernateBlobStoreFactory<K, V> setHibernateProperties(Properties hibernateProps) {
-        this.hibernateProps = hibernateProps;
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(CacheHibernateBlobStoreFactory.class, this);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java
deleted file mode 100644
index 0f5a33c..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreSessionListener.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.store.hibernate;
-
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
-import javax.cache.integration.CacheWriterException;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.cache.store.CacheStore;
-import org.apache.ignite.cache.store.CacheStoreSession;
-import org.apache.ignite.cache.store.CacheStoreSessionListener;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lifecycle.LifecycleAware;
-import org.apache.ignite.resources.LoggerResource;
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.Transaction;
-import org.hibernate.cfg.Configuration;
-
-/**
- * Hibernate-based cache store session listener.
- * <p>
- * This listener creates a new Hibernate session for each store
- * session. If there is an ongoing cache transaction, a corresponding
- * Hibernate transaction is created as well.
- * <p>
- * The Hibernate session is saved as a store session
- * {@link CacheStoreSession#attachment() attachment}.
- * The listener guarantees that the session will be
- * available for any store operation. If there is an
- * ongoing cache transaction, all operations within this
- * transaction will share a DB transaction.
- * <p>
- * As an example, here is how the {@link CacheStore#write(javax.cache.Cache.Entry)}
- * method can be implemented if {@link CacheHibernateStoreSessionListener}
- * is configured:
- * <pre name="code" class="java">
- * private static class Store extends CacheStoreAdapter&lt;Integer, Integer&gt; {
- *     &#64;CacheStoreSessionResource
- *     private CacheStoreSession ses;
- *
- *     &#64;Override public void write(Cache.Entry&lt;? extends Integer, ? extends Integer&gt; entry) throws CacheWriterException {
- *         // Get Hibernate session from the current store session.
- *         Session hibSes = ses.attachment();
- *
- *         // Persist the value.
- *         hibSes.persist(entry.getValue());
- *     }
- * }
- * </pre>
- * Hibernate session will be automatically created by the listener
- * at the start of the session and closed when it ends.
- * <p>
- * {@link CacheHibernateStoreSessionListener} requires that either
- * {@link #setSessionFactory(SessionFactory)} session factory}
- * or {@link #setHibernateConfigurationPath(String) Hibernate configuration file}
- * is provided. If non of them is set, exception is thrown. Is both are provided,
- * session factory will be used.
- */
-public class CacheHibernateStoreSessionListener implements CacheStoreSessionListener, LifecycleAware {
-    /** Hibernate session factory. */
-    private SessionFactory sesFactory;
-
-    /** Hibernate configuration file path. */
-    private String hibernateCfgPath;
-
-    /** Logger. */
-    @LoggerResource
-    private IgniteLogger log;
-
-    /** Whether to close session on stop. */
-    private boolean closeSesOnStop;
-
-    /**
-     * Sets Hibernate session factory.
-     * <p>
-     * Either session factory or configuration file is required.
-     * If none is provided, exception will be thrown on startup.
-     *
-     * @param sesFactory Session factory.
-     */
-    public void setSessionFactory(SessionFactory sesFactory) {
-        this.sesFactory = sesFactory;
-    }
-
-    /**
-     * Gets Hibernate session factory.
-     *
-     * @return Session factory.
-     */
-    public SessionFactory getSessionFactory() {
-        return sesFactory;
-    }
-
-    /**
-     * Sets hibernate configuration path.
-     * <p>
-     * Either session factory or configuration file is required.
-     * If none is provided, exception will be thrown on startup.
-     *
-     * @param hibernateCfgPath Hibernate configuration path.
-     */
-    public void setHibernateConfigurationPath(String hibernateCfgPath) {
-        this.hibernateCfgPath = hibernateCfgPath;
-    }
-
-    /**
-     * Gets hibernate configuration path.
-     *
-     * @return Hibernate configuration path.
-     */
-    public String getHibernateConfigurationPath() {
-        return hibernateCfgPath;
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("deprecation")
-    @Override public void start() throws IgniteException {
-        if (sesFactory == null && F.isEmpty(hibernateCfgPath))
-            throw new IgniteException("Either session factory or Hibernate configuration file is required by " +
-                getClass().getSimpleName() + '.');
-
-        if (!F.isEmpty(hibernateCfgPath)) {
-            if (sesFactory == null) {
-                try {
-                    URL url = new URL(hibernateCfgPath);
-
-                    sesFactory = new Configuration().configure(url).buildSessionFactory();
-                }
-                catch (MalformedURLException ignored) {
-                    // No-op.
-                }
-
-                if (sesFactory == null) {
-                    File cfgFile = new File(hibernateCfgPath);
-
-                    if (cfgFile.exists())
-                        sesFactory = new Configuration().configure(cfgFile).buildSessionFactory();
-                }
-
-                if (sesFactory == null)
-                    sesFactory = new Configuration().configure(hibernateCfgPath).buildSessionFactory();
-
-                if (sesFactory == null)
-                    throw new IgniteException("Failed to resolve Hibernate configuration file: " + hibernateCfgPath);
-
-                closeSesOnStop = true;
-            }
-            else
-                U.warn(log, "Hibernate configuration file configured in " + getClass().getSimpleName() +
-                    " will be ignored (session factory is already set).");
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void stop() throws IgniteException {
-        if (closeSesOnStop && sesFactory != null && !sesFactory.isClosed())
-            sesFactory.close();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void onSessionStart(CacheStoreSession ses) {
-        if (ses.attachment() == null) {
-            try {
-                Session hibSes = sesFactory.openSession();
-
-                ses.attach(hibSes);
-
-                if (ses.isWithinTransaction())
-                    hibSes.beginTransaction();
-            }
-            catch (HibernateException e) {
-                throw new CacheWriterException("Failed to start store session [tx=" + ses.transaction() + ']', e);
-            }
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void onSessionEnd(CacheStoreSession ses, boolean commit) {
-        Session hibSes = ses.attach(null);
-
-        if (hibSes != null) {
-            try {
-                Transaction tx = hibSes.getTransaction();
-
-                if (commit) {
-                    if (hibSes.isDirty())
-                        hibSes.flush();
-
-                    if (tx.isActive())
-                        tx.commit();
-                }
-                else if (tx.isActive())
-                    tx.rollback();
-            }
-            catch (HibernateException e) {
-                throw new CacheWriterException("Failed to end store session [tx=" + ses.transaction() + ']', e);
-            }
-            finally {
-                hibSes.close();
-            }
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/package-info.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/package-info.java b/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/package-info.java
deleted file mode 100644
index 891d99a..0000000
--- a/modules/hibernate5/src/main/java/org/apache/ignite/cache/store/hibernate/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * <!-- Package description. -->
- * Contains reference Hibernate-based cache store implementation.
- */
-package org.apache.ignite.cache.store.hibernate;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/test/config/factory-cache.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/test/config/factory-cache.xml b/modules/hibernate5/src/test/config/factory-cache.xml
deleted file mode 100644
index a251846..0000000
--- a/modules/hibernate5/src/test/config/factory-cache.xml
+++ /dev/null
@@ -1,59 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one or more
-  contributor license agreements.  See the NOTICE file distributed with
-  this work for additional information regarding copyright ownership.
-  The ASF licenses this file to You under the Apache License, Version 2.0
-  (the "License"); you may not use this file except in compliance with
-  the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-<beans xmlns="http://www.springframework.org/schema/beans"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="
-        http://www.springframework.org/schema/beans
-        http://www.springframework.org/schema/beans/spring-beans.xsd">
-
-    <bean id="simpleSessionFactory"
-          class="org.apache.ignite.cache.store.hibernate.CacheHibernateStoreFactorySelfTest$DummySessionFactoryExt"/>
-
-    <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
-        <property name="cacheConfiguration">
-            <list>
-                <bean class="org.apache.ignite.configuration.CacheConfiguration">
-                    <property name="name" value="test"/>
-                    <property name="atomicityMode" value="ATOMIC"/>
-                    <property name="backups" value="1"/>
-                    <property name="cacheStoreFactory">
-                        <bean class="org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory">
-                            <property name="sessionFactoryBean" value = "simpleSessionFactory"/>
-                        </bean>
-                    </property>
-                </bean>
-            </list>
-        </property>
-
-        <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
-        <property name="discoverySpi">
-            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
-                <property name="ipFinder">
-                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
-                        <property name="addresses">
-                            <list>
-                                <value>127.0.0.1:47500..47509</value>
-                            </list>
-                        </property>
-                    </bean>
-                </property>
-            </bean>
-        </property>
-    </bean>
-</beans>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/test/config/factory-cache1.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/test/config/factory-cache1.xml b/modules/hibernate5/src/test/config/factory-cache1.xml
deleted file mode 100644
index 7a53b1f..0000000
--- a/modules/hibernate5/src/test/config/factory-cache1.xml
+++ /dev/null
@@ -1,61 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one or more
-  contributor license agreements.  See the NOTICE file distributed with
-  this work for additional information regarding copyright ownership.
-  The ASF licenses this file to You under the Apache License, Version 2.0
-  (the "License"); you may not use this file except in compliance with
-  the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-<beans xmlns="http://www.springframework.org/schema/beans"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="
-        http://www.springframework.org/schema/beans
-        http://www.springframework.org/schema/beans/spring-beans.xsd">
-
-    <bean id="simpleSessionFactory1"
-          class="org.apache.ignite.cache.store.hibernate.CacheHibernateStoreFactorySelfTest$DummySessionFactory"/>
-
-    <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
-        <property name="igniteInstanceName" value="ignite1"/>
-
-        <property name="cacheConfiguration">
-            <list>
-                <bean class="org.apache.ignite.configuration.CacheConfiguration">
-                    <property name="name" value="test"/>
-                    <property name="atomicityMode" value="ATOMIC"/>
-                    <property name="backups" value="1"/>
-                    <property name="cacheStoreFactory">
-                        <bean class="org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory">
-                            <property name="sessionFactoryBean" value = "simpleSessionFactory1"/>
-                        </bean>
-                    </property>
-                </bean>
-            </list>
-        </property>
-
-        <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
-        <property name="discoverySpi">
-            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
-                <property name="ipFinder">
-                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
-                        <property name="addresses">
-                            <list>
-                                <value>127.0.0.1:47500..47509</value>
-                            </list>
-                        </property>
-                    </bean>
-                </property>
-            </bean>
-        </property>
-    </bean>
-</beans>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/test/config/factory-incorrect-store-cache.xml
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/test/config/factory-incorrect-store-cache.xml b/modules/hibernate5/src/test/config/factory-incorrect-store-cache.xml
deleted file mode 100644
index 459930c..0000000
--- a/modules/hibernate5/src/test/config/factory-incorrect-store-cache.xml
+++ /dev/null
@@ -1,56 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one or more
-  contributor license agreements.  See the NOTICE file distributed with
-  this work for additional information regarding copyright ownership.
-  The ASF licenses this file to You under the Apache License, Version 2.0
-  (the "License"); you may not use this file except in compliance with
-  the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-<beans xmlns="http://www.springframework.org/schema/beans"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="
-        http://www.springframework.org/schema/beans
-        http://www.springframework.org/schema/beans/spring-beans.xsd">
-
-    <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
-        <property name="cacheConfiguration">
-            <list>
-                <bean class="org.apache.ignite.configuration.CacheConfiguration">
-                    <property name="name" value="test"/>
-                    <property name="atomicityMode" value="ATOMIC"/>
-                    <property name="backups" value="1"/>
-                    <property name="cacheStoreFactory">
-                        <bean class="org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreFactory">
-                            <property name="sessionFactoryBean" value = "simpleSessionFactory1"/>
-                        </bean>
-                    </property>
-                </bean>
-            </list>
-        </property>
-
-        <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
-        <property name="discoverySpi">
-            <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
-                <property name="ipFinder">
-                    <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
-                        <property name="addresses">
-                            <list>
-                                <value>127.0.0.1:47500..47509</value>
-                            </list>
-                        </property>
-                    </bean>
-                </property>
-            </bean>
-        </property>
-    </bean>
-</beans>

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate5/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheConfigurationSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate5/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheConfigurationSelfTest.java b/modules/hibernate5/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheConfigurationSelfTest.java
deleted file mode 100644
index 0cb36e9..0000000
--- a/modules/hibernate5/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheConfigurationSelfTest.java
+++ /dev/null
@@ -1,409 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import javax.cache.Cache;
-import javax.persistence.Cacheable;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.Transaction;
-import org.hibernate.annotations.CacheConcurrencyStrategy;
-import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cfg.Configuration;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-import static org.apache.ignite.cache.hibernate.HibernateRegionFactory.DFLT_ACCESS_TYPE_PROPERTY;
-import static org.apache.ignite.cache.hibernate.HibernateRegionFactory.DFLT_CACHE_NAME_PROPERTY;
-import static org.apache.ignite.cache.hibernate.HibernateRegionFactory.IGNITE_INSTANCE_NAME_PROPERTY;
-import static org.apache.ignite.cache.hibernate.HibernateRegionFactory.REGION_CACHE_PROPERTY;
-import static org.hibernate.cfg.AvailableSettings.CACHE_REGION_FACTORY;
-import static org.hibernate.cfg.AvailableSettings.GENERATE_STATISTICS;
-import static org.hibernate.cfg.AvailableSettings.HBM2DDL_AUTO;
-import static org.hibernate.cfg.AvailableSettings.RELEASE_CONNECTIONS;
-import static org.hibernate.cfg.AvailableSettings.USE_QUERY_CACHE;
-import static org.hibernate.cfg.AvailableSettings.USE_SECOND_LEVEL_CACHE;
-
-/**
- * Tests Hibernate L2 cache configuration.
- */
-public class HibernateL2CacheConfigurationSelfTest extends GridCommonAbstractTest {
-    /** */
-    public static final String ENTITY1_NAME = Entity1.class.getName();
-
-    /** */
-    public static final String ENTITY2_NAME = Entity2.class.getName();
-
-    /** */
-    public static final String ENTITY3_NAME = Entity3.class.getName();
-
-    /** */
-    public static final String ENTITY4_NAME = Entity4.class.getName();
-
-    /** */
-    public static final String TIMESTAMP_CACHE = "org.hibernate.cache.spi.UpdateTimestampsCache";
-
-    /** */
-    public static final String QUERY_CACHE = "org.hibernate.cache.internal.StandardQueryCache";
-
-    /** */
-    public static final String CONNECTION_URL = "jdbc:h2:mem:example;DB_CLOSE_DELAY=-1";
-
-    /** If {@code true} then sets default cache in configuration. */
-    private boolean dfltCache;
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        startGrid(0);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        stopAllGrids();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        for (IgniteCacheProxy<?, ?> cache : ((IgniteKernal)grid(0)).caches())
-            cache.clear();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
-
-        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
-
-        discoSpi.setIpFinder(new TcpDiscoveryVmIpFinder(true));
-
-        cfg.setDiscoverySpi(discoSpi);
-
-        cfg.setCacheConfiguration(cacheConfiguration(ENTITY3_NAME), cacheConfiguration(ENTITY4_NAME),
-            cacheConfiguration("cache1"), cacheConfiguration("cache2"), cacheConfiguration("cache3"),
-            cacheConfiguration(TIMESTAMP_CACHE), cacheConfiguration(QUERY_CACHE));
-
-        return cfg;
-    }
-
-    /**
-     * @param cacheName Cache name.
-     * @return Cache configuration.
-     */
-    private CacheConfiguration cacheConfiguration(String cacheName) {
-        CacheConfiguration cfg = new CacheConfiguration();
-
-        cfg.setName(cacheName);
-
-        cfg.setCacheMode(PARTITIONED);
-
-        cfg.setAtomicityMode(ATOMIC);
-
-        return cfg;
-    }
-    /**
-     * @param igniteInstanceName Ignite instance name.
-     * @return Hibernate configuration.
-     */
-    protected Configuration hibernateConfiguration(String igniteInstanceName) {
-        Configuration cfg = new Configuration();
-
-        cfg.addAnnotatedClass(Entity1.class);
-        cfg.addAnnotatedClass(Entity2.class);
-        cfg.addAnnotatedClass(Entity3.class);
-        cfg.addAnnotatedClass(Entity4.class);
-
-        cfg.setProperty(DFLT_ACCESS_TYPE_PROPERTY, AccessType.NONSTRICT_READ_WRITE.name());
-
-        cfg.setProperty(HBM2DDL_AUTO, "create");
-
-        cfg.setProperty(GENERATE_STATISTICS, "true");
-
-        cfg.setProperty(USE_SECOND_LEVEL_CACHE, "true");
-
-        cfg.setProperty(USE_QUERY_CACHE, "true");
-
-        cfg.setProperty(CACHE_REGION_FACTORY, HibernateRegionFactory.class.getName());
-
-        cfg.setProperty(RELEASE_CONNECTIONS, "on_close");
-
-        cfg.setProperty(IGNITE_INSTANCE_NAME_PROPERTY, igniteInstanceName);
-
-        cfg.setProperty(REGION_CACHE_PROPERTY + ENTITY1_NAME, "cache1");
-        cfg.setProperty(REGION_CACHE_PROPERTY + ENTITY2_NAME, "cache2");
-        cfg.setProperty(REGION_CACHE_PROPERTY + TIMESTAMP_CACHE, TIMESTAMP_CACHE);
-        cfg.setProperty(REGION_CACHE_PROPERTY + QUERY_CACHE, QUERY_CACHE);
-
-        if (dfltCache)
-            cfg.setProperty(DFLT_CACHE_NAME_PROPERTY, "cache3");
-
-        return cfg;
-    }
-
-    /**
-     * Tests property {@link HibernateRegionFactory#REGION_CACHE_PROPERTY}.
-     */
-    public void testPerRegionCacheProperty() {
-        testCacheUsage(1, 1, 0, 1, 1);
-    }
-
-    /**
-     * Tests property {@link HibernateRegionFactory#DFLT_CACHE_NAME_PROPERTY}.
-     */
-    public void testDefaultCache() {
-        dfltCache = true;
-
-        testCacheUsage(1, 1, 2, 0, 0);
-    }
-
-    /**
-     * @param expCache1 Expected size of cache with name 'cache1'.
-     * @param expCache2 Expected size of cache with name 'cache2'.
-     * @param expCache3 Expected size of cache with name 'cache3'.
-     * @param expCacheE3 Expected size of cache with name {@link #ENTITY3_NAME}.
-     * @param expCacheE4 Expected size of cache with name {@link #ENTITY4_NAME}.
-     */
-    @SuppressWarnings("unchecked")
-    private void testCacheUsage(int expCache1, int expCache2, int expCache3, int expCacheE3, int expCacheE4) {
-        SessionFactory sesFactory = startHibernate(getTestIgniteInstanceName(0));
-
-        try {
-            Session ses = sesFactory.openSession();
-
-            try {
-                Transaction tx = ses.beginTransaction();
-
-                ses.save(new Entity1());
-                ses.save(new Entity2());
-                ses.save(new Entity3());
-                ses.save(new Entity4());
-
-                tx.commit();
-            }
-            finally {
-                ses.close();
-            }
-
-            ses = sesFactory.openSession();
-
-            try {
-                List<Entity1> list1 = ses.createCriteria(ENTITY1_NAME).list();
-
-                assertEquals(1, list1.size());
-
-                for (Entity1 e : list1) {
-                    ses.load(ENTITY1_NAME, e.getId());
-                    assertNotNull(e.getId());
-                }
-
-                List<Entity2> list2 = ses.createCriteria(ENTITY2_NAME).list();
-
-                assertEquals(1, list2.size());
-
-                for (Entity2 e : list2)
-                    assertNotNull(e.getId());
-
-                List<Entity3> list3 = ses.createCriteria(ENTITY3_NAME).list();
-
-                assertEquals(1, list3.size());
-
-                for (Entity3 e : list3)
-                    assertNotNull(e.getId());
-
-                List<Entity4> list4 = ses.createCriteria(ENTITY4_NAME).list();
-
-                assertEquals(1, list4.size());
-
-                for (Entity4 e : list4)
-                    assertNotNull(e.getId());
-            }
-            finally {
-                ses.close();
-            }
-
-            IgniteCache<Object, Object> cache1 = grid(0).cache("cache1");
-            IgniteCache<Object, Object> cache2 = grid(0).cache("cache2");
-            IgniteCache<Object, Object> cache3 = grid(0).cache("cache3");
-            IgniteCache<Object, Object> cacheE3 = grid(0).cache(ENTITY3_NAME);
-            IgniteCache<Object, Object> cacheE4 = grid(0).cache(ENTITY4_NAME);
-
-            assertEquals("Unexpected entries: " + toSet(cache1.iterator()), expCache1, cache1.size());
-            assertEquals("Unexpected entries: " + toSet(cache2.iterator()), expCache2, cache2.size());
-            assertEquals("Unexpected entries: " + toSet(cache3.iterator()), expCache3, cache3.size());
-            assertEquals("Unexpected entries: " + toSet(cacheE3.iterator()), expCacheE3, cacheE3.size());
-            assertEquals("Unexpected entries: " + toSet(cacheE4.iterator()), expCacheE4, cacheE4.size());
-        }
-        finally {
-            sesFactory.close();
-        }
-    }
-
-    /**
-     *
-     */
-    private <K, V> Set<Cache.Entry<K, V>> toSet(Iterator<Cache.Entry<K, V>> iter){
-        Set<Cache.Entry<K, V>> set = new HashSet<>();
-
-        while (iter.hasNext())
-            set.add(iter.next());
-
-        return set;
-    }
-
-    /**
-     * @param igniteInstanceName Name of the grid providing caches.
-     * @return Session factory.
-     */
-    private SessionFactory startHibernate(String igniteInstanceName) {
-        Configuration cfg = hibernateConfiguration(igniteInstanceName);
-
-        StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
-
-        builder.applySetting("hibernate.connection.url", CONNECTION_URL);
-        builder.applySetting("hibernate.show_sql", false);
-        builder.applySettings(cfg.getProperties());
-
-        return cfg.buildSessionFactory(builder.build());
-    }
-
-    /**
-     * Test Hibernate entity1.
-     */
-    @javax.persistence.Entity
-    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
-    @Cacheable
-    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
-    public static class Entity1 {
-        /** */
-        private int id;
-
-        /**
-         * @return ID.
-         */
-        @Id
-        @GeneratedValue
-        public int getId() {
-            return id;
-        }
-
-        /**
-         * @param id ID.
-         */
-        public void setId(int id) {
-            this.id = id;
-        }
-    }
-
-    /**
-     * Test Hibernate entity2.
-     */
-    @javax.persistence.Entity
-    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
-    @Cacheable
-    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
-    public static class Entity2 {
-        /** */
-        private int id;
-
-        /**
-         * @return ID.
-         */
-        @Id
-        @GeneratedValue
-        public int getId() {
-            return id;
-        }
-
-        /**
-         * @param id ID.
-         */
-        public void setId(int id) {
-            this.id = id;
-        }
-    }
-
-    /**
-     * Test Hibernate entity3.
-     */
-    @javax.persistence.Entity
-    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
-    @Cacheable
-    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
-    public static class Entity3 {
-        /** */
-        private int id;
-
-        /**
-         * @return ID.
-         */
-        @Id
-        @GeneratedValue
-        public int getId() {
-            return id;
-        }
-
-        /**
-         * @param id ID.
-         */
-        public void setId(int id) {
-            this.id = id;
-        }
-    }
-
-    /**
-     * Test Hibernate entity4.
-     */
-    @javax.persistence.Entity
-    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
-    @Cacheable
-    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
-    public static class Entity4 {
-        /** */
-        private int id;
-
-        /**
-         * @return ID.
-         */
-        @Id
-        @GeneratedValue
-        public int getId() {
-            return id;
-        }
-
-        /**
-         * @param id ID.
-         */
-        public void setId(int id) {
-            this.id = id;
-        }
-    }
-}
\ No newline at end of file


[14/16] ignite git commit: ignite-1794 Refactored hibernate modules, switched to hibernate 5.1

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java
new file mode 100644
index 0000000..7ac790c
--- /dev/null
+++ b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java
@@ -0,0 +1,1954 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.hibernate.ObjectNotFoundException;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.StaleObjectStateException;
+import org.hibernate.Transaction;
+import org.hibernate.annotations.NaturalId;
+import org.hibernate.annotations.NaturalIdCache;
+import org.hibernate.cache.spi.GeneralDataRegion;
+import org.hibernate.cache.spi.TransactionalDataRegion;
+import org.hibernate.cache.spi.access.AccessType;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.exception.ConstraintViolationException;
+import org.hibernate.service.ServiceRegistryBuilder;
+import org.hibernate.stat.NaturalIdCacheStatistics;
+import org.hibernate.stat.SecondLevelCacheStatistics;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.DFLT_ACCESS_TYPE_PROPERTY;
+import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.IGNITE_INSTANCE_NAME_PROPERTY;
+import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.REGION_CACHE_PROPERTY;
+import static org.hibernate.cfg.Environment.CACHE_REGION_FACTORY;
+import static org.hibernate.cfg.Environment.GENERATE_STATISTICS;
+import static org.hibernate.cfg.Environment.HBM2DDL_AUTO;
+import static org.hibernate.cfg.Environment.RELEASE_CONNECTIONS;
+import static org.hibernate.cfg.Environment.USE_QUERY_CACHE;
+import static org.hibernate.cfg.Environment.USE_SECOND_LEVEL_CACHE;
+
+/**
+ *
+ * Tests Hibernate L2 cache.
+ */
+public class HibernateL2CacheSelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    public static final String CONNECTION_URL = "jdbc:h2:mem:example;DB_CLOSE_DELAY=-1";
+
+    /** */
+    public static final String ENTITY_NAME = Entity.class.getName();
+
+    /** */
+    public static final String ENTITY2_NAME = Entity2.class.getName();
+
+    /** */
+    public static final String VERSIONED_ENTITY_NAME = VersionedEntity.class.getName();
+
+    /** */
+    public static final String PARENT_ENTITY_NAME = ParentEntity.class.getName();
+
+    /** */
+    public static final String CHILD_COLLECTION_REGION = ENTITY_NAME + ".children";
+
+    /** */
+    public static final String NATURAL_ID_REGION =
+        "org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest$Entity##NaturalId";
+
+    /** */
+    public static final String NATURAL_ID_REGION2 =
+        "org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest$Entity2##NaturalId";
+
+    /** */
+    private SessionFactory sesFactory1;
+
+    /** */
+    private SessionFactory sesFactory2;
+
+    /**
+     * First Hibernate test entity.
+     */
+    @javax.persistence.Entity
+    @NaturalIdCache
+    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
+    public static class Entity {
+        /** */
+        private int id;
+
+        /** */
+        private String name;
+
+        /** */
+        private Collection<ChildEntity> children;
+
+        /**
+         * Default constructor required by Hibernate.
+         */
+        public Entity() {
+            // No-op.
+        }
+
+        /**
+         * @param id ID.
+         * @param name Name.
+         */
+        public Entity(int id, String name) {
+            this.id = id;
+            this.name = name;
+        }
+
+        /**
+         * @return ID.
+         */
+        @Id
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(int id) {
+            this.id = id;
+        }
+
+        /**
+         * @return Name.
+         */
+        @NaturalId(mutable = true)
+        public String getName() {
+            return name;
+        }
+
+        /**
+         * @param name Name.
+         */
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        /**
+         * @return Children.
+         */
+        @OneToMany(cascade=javax.persistence.CascadeType.ALL, fetch=FetchType.LAZY)
+        @JoinColumn(name="ENTITY_ID")
+        public Collection<ChildEntity> getChildren() {
+            return children;
+        }
+
+        /**
+         * @param children Children.
+         */
+        public void setChildren(Collection<ChildEntity> children) {
+            this.children = children;
+        }
+    }
+
+    /**
+     * Second Hibernate test entity.
+     */
+    @javax.persistence.Entity
+    @NaturalIdCache
+    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
+    public static class Entity2 {
+        /** */
+        private int id;
+
+        /** */
+        private String name;
+
+        /** */
+        private Collection<ChildEntity> children;
+
+        /**
+         * Default constructor required by Hibernate.
+         */
+        public Entity2() {
+            // No-op.
+        }
+
+        /**
+         * @param id ID.
+         * @param name Name.
+         */
+        public Entity2(int id, String name) {
+            this.id = id;
+            this.name = name;
+        }
+
+        /**
+         * @return ID.
+         */
+        @Id
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(int id) {
+            this.id = id;
+        }
+
+        /**
+         * @return Name.
+         */
+        @NaturalId(mutable = true)
+        public String getName() {
+            return name;
+        }
+
+        /**
+         * @param name Name.
+         */
+        public void setName(String name) {
+            this.name = name;
+        }
+    }
+
+    /**
+     * Hibernate child entity referenced by {@link Entity}.
+     */
+    @javax.persistence.Entity
+    @SuppressWarnings("PublicInnerClass")
+    public static class ChildEntity {
+        /** */
+        private int id;
+
+        /**
+         * Default constructor required by Hibernate.
+         */
+        public ChildEntity() {
+            // No-op.
+        }
+
+        /**
+         * @param id ID.
+         */
+        public ChildEntity(int id) {
+            this.id = id;
+        }
+
+        /**
+         * @return ID.
+         */
+        @Id
+        @GeneratedValue
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(int id) {
+            this.id = id;
+        }
+    }
+
+    /**
+     * Hibernate entity referencing {@link Entity}.
+     */
+    @javax.persistence.Entity
+    @SuppressWarnings("PublicInnerClass")
+    public static class ParentEntity {
+        /** */
+        private int id;
+
+        /** */
+        private Entity entity;
+
+        /**
+         * Default constructor required by Hibernate.
+         */
+        public ParentEntity() {
+            // No-op.
+        }
+
+        /**
+         * @param id ID.
+         * @param entity Referenced entity.
+         */
+        public ParentEntity(int id, Entity entity) {
+            this.id = id;
+            this.entity = entity;
+        }
+
+        /**
+         * @return ID.
+         */
+        @Id
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(int id) {
+            this.id = id;
+        }
+
+        /**
+         * @return Referenced entity.
+         */
+        @OneToOne
+        public Entity getEntity() {
+            return entity;
+        }
+
+        /**
+         * @param entity Referenced entity.
+         */
+        public void setEntity(Entity entity) {
+            this.entity = entity;
+        }
+    }
+
+    /**
+     * Hibernate entity.
+     */
+    @javax.persistence.Entity
+    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
+    public static class VersionedEntity {
+        /** */
+        private int id;
+
+        /** */
+        private long ver;
+
+        /**
+         * Default constructor required by Hibernate.
+         */
+        public VersionedEntity() {
+        }
+
+        /**
+         * @param id ID.
+         */
+        public VersionedEntity(int id) {
+            this.id = id;
+        }
+
+        /**
+         * @return ID.
+         */
+        @Id
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(int id) {
+            this.id = id;
+        }
+
+        /**
+         * @return Version.
+         */
+        @javax.persistence.Version
+        public long getVersion() {
+            return ver;
+        }
+
+        /**
+         * @param ver Version.
+         */
+        public void setVersion(long ver) {
+            this.ver = ver;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
+
+        discoSpi.setIpFinder(IP_FINDER);
+
+        cfg.setDiscoverySpi(discoSpi);
+
+        cfg.setCacheConfiguration(generalRegionConfiguration("org.hibernate.cache.spi.UpdateTimestampsCache"),
+            generalRegionConfiguration("org.hibernate.cache.internal.StandardQueryCache"),
+            transactionalRegionConfiguration(ENTITY_NAME),
+            transactionalRegionConfiguration(ENTITY2_NAME),
+            transactionalRegionConfiguration(VERSIONED_ENTITY_NAME),
+            transactionalRegionConfiguration(PARENT_ENTITY_NAME),
+            transactionalRegionConfiguration(CHILD_COLLECTION_REGION),
+            transactionalRegionConfiguration(NATURAL_ID_REGION),
+            transactionalRegionConfiguration(NATURAL_ID_REGION2));
+
+        return cfg;
+    }
+
+    /**
+     * @param regionName Region name.
+     * @return Cache configuration for {@link GeneralDataRegion}.
+     */
+    private CacheConfiguration generalRegionConfiguration(String regionName) {
+        CacheConfiguration cfg = new CacheConfiguration();
+
+        cfg.setName(regionName);
+
+        cfg.setCacheMode(PARTITIONED);
+
+        cfg.setAtomicityMode(ATOMIC);
+
+        cfg.setWriteSynchronizationMode(FULL_SYNC);
+
+        cfg.setBackups(1);
+
+        cfg.setAffinity(new RendezvousAffinityFunction(false, 10));
+
+        return cfg;
+    }
+
+    /**
+     * @param regionName Region name.
+     * @return Cache configuration for {@link TransactionalDataRegion}.
+     */
+    protected CacheConfiguration transactionalRegionConfiguration(String regionName) {
+        CacheConfiguration cfg = new CacheConfiguration();
+
+        cfg.setName(regionName);
+
+        cfg.setCacheMode(PARTITIONED);
+
+        cfg.setAtomicityMode(TRANSACTIONAL);
+
+        cfg.setWriteSynchronizationMode(FULL_SYNC);
+
+        cfg.setBackups(1);
+
+        cfg.setAffinity(new RendezvousAffinityFunction(false, 10));
+
+        return cfg;
+    }
+
+    /**
+     * @param accessType Hibernate L2 cache access type.
+     * @param igniteInstanceName Ignite instance name.
+     * @return Hibernate configuration.
+     */
+    private Configuration hibernateConfiguration(AccessType accessType,
+        String igniteInstanceName) {
+        Configuration cfg = new Configuration();
+
+        cfg.addAnnotatedClass(Entity.class);
+        cfg.addAnnotatedClass(Entity2.class);
+        cfg.addAnnotatedClass(VersionedEntity.class);
+        cfg.addAnnotatedClass(ChildEntity.class);
+        cfg.addAnnotatedClass(ParentEntity.class);
+
+        cfg.setCacheConcurrencyStrategy(ENTITY_NAME, accessType.getExternalName());
+        cfg.setCacheConcurrencyStrategy(ENTITY2_NAME, accessType.getExternalName());
+        cfg.setCacheConcurrencyStrategy(VERSIONED_ENTITY_NAME, accessType.getExternalName());
+        cfg.setCacheConcurrencyStrategy(PARENT_ENTITY_NAME, accessType.getExternalName());
+        cfg.setCollectionCacheConcurrencyStrategy(CHILD_COLLECTION_REGION, accessType.getExternalName());
+
+        for (Map.Entry<String, String> e : hibernateProperties(igniteInstanceName, accessType.name()).entrySet())
+            cfg.setProperty(e.getKey(), e.getValue());
+
+        // Use the same cache for Entity and Entity2.
+        cfg.setProperty(REGION_CACHE_PROPERTY + ENTITY2_NAME, ENTITY_NAME);
+
+        return cfg;
+    }
+
+    /**
+     * @return Hibernate registry builder.
+     */
+    protected ServiceRegistryBuilder registryBuilder() {
+        ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
+
+        builder.applySetting("hibernate.connection.url", CONNECTION_URL);
+
+        return builder;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrids(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        cleanup();
+    }
+
+    /**
+     * @return Hibernate L2 cache access types to test.
+     */
+    protected AccessType[] accessTypes() {
+        return new AccessType[]{AccessType.READ_ONLY, AccessType.NONSTRICT_READ_WRITE, AccessType.READ_WRITE};
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCollectionCache() throws Exception {
+        for (AccessType accessType : accessTypes())
+            testCollectionCache(accessType);
+    }
+
+    /**
+     * @param accessType Cache access type.
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings("unchecked")
+    private void testCollectionCache(AccessType accessType) throws Exception {
+        createSessionFactories(accessType);
+
+        Map<Integer, Integer> idToChildCnt = new HashMap<>();
+
+        try {
+            Session ses = sesFactory1.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                for (int i = 0; i < 3; i++) {
+                    Entity e = new Entity(i, "name-" + i);
+
+                    Collection<ChildEntity> children = new ArrayList<>();
+
+                    for (int j = 0; j < 3; j++)
+                        children.add(new ChildEntity());
+
+                    e.setChildren(children);
+
+                    idToChildCnt.put(e.getId(), e.getChildren().size());
+
+                    ses.save(e);
+                }
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            // Load children, this should populate cache.
+
+            ses = sesFactory1.openSession();
+
+            try {
+                List<Entity> list = ses.createCriteria(ENTITY_NAME).list();
+
+                assertEquals(idToChildCnt.size(), list.size());
+
+                for (Entity e : list)
+                    assertEquals((int)idToChildCnt.get(e.getId()), e.getChildren().size());
+            }
+            finally {
+                ses.close();
+            }
+
+            assertCollectionCache(sesFactory2, idToChildCnt, 3, 0);
+            assertCollectionCache(sesFactory1, idToChildCnt, 3, 0);
+
+            if (accessType == AccessType.READ_ONLY)
+                return;
+
+            // Update children for one entity.
+
+            ses = sesFactory1.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                Entity e1 = (Entity)ses.load(Entity.class, 1);
+
+                e1.getChildren().remove(e1.getChildren().iterator().next());
+
+                ses.update(e1);
+
+                idToChildCnt.put(e1.getId(), e1.getChildren().size());
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertCollectionCache(sesFactory2, idToChildCnt, 2, 1); // After update collection cache entry is removed.
+            assertCollectionCache(sesFactory1, idToChildCnt, 3, 0); // 'assertCollectionCache' loads children in cache.
+
+            // Update children for the same entity using another SessionFactory.
+
+            ses = sesFactory2.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                Entity e1 = (Entity)ses.load(Entity.class, 1);
+
+                e1.getChildren().remove(e1.getChildren().iterator().next());
+
+                ses.update(e1);
+
+                idToChildCnt.put(e1.getId(), e1.getChildren().size());
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertCollectionCache(sesFactory2, idToChildCnt, 2, 1); // After update collection cache entry is removed.
+            assertCollectionCache(sesFactory1, idToChildCnt, 3, 0); // 'assertCollectionCache' loads children in cache.
+        }
+        finally {
+            cleanup();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testEntityCache() throws Exception {
+        for (AccessType accessType : accessTypes())
+            testEntityCache(accessType);
+    }
+
+    /**
+     * @param accessType Cache access type.
+     * @throws Exception If failed.
+     */
+    private void testEntityCache(AccessType accessType) throws Exception {
+        createSessionFactories(accessType);
+
+        Map<Integer, String> idToName = new HashMap<>();
+
+        try {
+            Session ses = sesFactory1.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                for (int i = 0; i < 2; i++) {
+                    String name = "name-" + i;
+
+                    ses.save(new Entity(i, name));
+
+                    idToName.put(i, name);
+                }
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName, 100);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName, 100);
+
+            if (accessType == AccessType.READ_ONLY)
+                return;
+
+            ses = sesFactory1.openSession();
+
+            try {
+                // Updates and inserts in single transaction.
+
+                Transaction tx = ses.beginTransaction();
+
+                Entity e0 = (Entity)ses.load(Entity.class, 0);
+
+                e0.setName("name-0-changed1");
+
+                ses.update(e0);
+
+                idToName.put(0, e0.getName());
+
+                ses.save(new Entity(2, "name-2"));
+
+                idToName.put(2, "name-2");
+
+                Entity e1 = (Entity)ses.load(Entity.class, 1);
+
+                e1.setName("name-1-changed1");
+
+                ses.update(e1);
+
+                idToName.put(1, e1.getName());
+
+                ses.save(new Entity(3, "name-3"));
+
+                idToName.put(3, "name-3");
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName);
+
+            ses = sesFactory1.openSession();
+
+            try {
+                // Updates, inserts and deletes in single transaction.
+
+                Transaction tx = ses.beginTransaction();
+
+                ses.save(new Entity(4, "name-4"));
+
+                idToName.put(4, "name-4");
+
+                Entity e0 = (Entity)ses.load(Entity.class, 0);
+
+                e0.setName("name-0-changed2");
+
+                ses.update(e0);
+
+                idToName.put(e0.getId(), e0.getName());
+
+                ses.delete(ses.load(Entity.class, 1));
+
+                idToName.remove(1);
+
+                Entity e2 = (Entity)ses.load(Entity.class, 2);
+
+                e2.setName("name-2-changed1");
+
+                ses.update(e2);
+
+                idToName.put(e2.getId(), e2.getName());
+
+                ses.delete(ses.load(Entity.class, 3));
+
+                idToName.remove(3);
+
+                ses.save(new Entity(5, "name-5"));
+
+                idToName.put(5, "name-5");
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName, 1, 3);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName, 1, 3);
+
+            // Try to update the same entity using another SessionFactory.
+
+            ses = sesFactory2.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                Entity e0 = (Entity)ses.load(Entity.class, 0);
+
+                e0.setName("name-0-changed3");
+
+                ses.update(e0);
+
+                idToName.put(e0.getId(), e0.getName());
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName);
+        }
+        finally {
+            cleanup();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTwoEntitiesSameCache() throws Exception {
+        for (AccessType accessType : accessTypes())
+            testTwoEntitiesSameCache(accessType);
+    }
+
+    /**
+     * @param accessType Cache access type.
+     * @throws Exception If failed.
+     */
+    private void testTwoEntitiesSameCache(AccessType accessType) throws Exception {
+        createSessionFactories(accessType);
+
+        try {
+            Session ses = sesFactory1.openSession();
+
+            Map<Integer, String> idToName1 = new HashMap<>();
+            Map<Integer, String> idToName2 = new HashMap<>();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                for (int i = 0; i < 2; i++) {
+                    String name = "name-" + i;
+
+                    ses.save(new Entity(i, name));
+                    ses.save(new Entity2(i, name));
+
+                    idToName1.put(i, name);
+                    idToName2.put(i, name);
+                }
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName1, 100);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName1, 100);
+
+            assertEntityCache(ENTITY2_NAME, sesFactory2, idToName2, 100);
+            assertEntityCache(ENTITY2_NAME, sesFactory1, idToName2, 100);
+
+            if (accessType == AccessType.READ_ONLY)
+                return;
+
+            ses = sesFactory1.openSession();
+
+            try {
+                // Updates both entities in single transaction.
+
+                Transaction tx = ses.beginTransaction();
+
+                Entity e = (Entity)ses.load(Entity.class, 0);
+
+                e.setName("name-0-changed1");
+
+                ses.update(e);
+
+                Entity2 e2 = (Entity2)ses.load(Entity2.class, 0);
+
+                e2.setName("name-e2-0-changed1");
+
+                ses.update(e2);
+
+                idToName1.put(0, e.getName());
+                idToName2.put(0, e2.getName());
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName1, 100);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName1, 100);
+
+            assertEntityCache(ENTITY2_NAME, sesFactory2, idToName2, 100);
+            assertEntityCache(ENTITY2_NAME, sesFactory1, idToName2, 100);
+
+            ses = sesFactory1.openSession();
+
+            try {
+                // Remove entity1 and insert entity2 in single transaction.
+
+                Transaction tx = ses.beginTransaction();
+
+                Entity e = (Entity)ses.load(Entity.class, 0);
+
+                ses.delete(e);
+
+                Entity2 e2 = new Entity2(2, "name-2");
+
+                ses.save(e2);
+
+                idToName1.remove(0);
+                idToName2.put(2, e2.getName());
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName1, 0, 100);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName1, 0, 100);
+
+            assertEntityCache(ENTITY2_NAME, sesFactory2, idToName2, 100);
+            assertEntityCache(ENTITY2_NAME, sesFactory1, idToName2, 100);
+
+            ses = sesFactory1.openSession();
+
+            Transaction tx = ses.beginTransaction();
+
+            try {
+                // Update, remove, insert in single transaction, transaction fails.
+
+                Entity e = (Entity)ses.load(Entity.class, 1);
+
+                e.setName("name-1-changed1");
+
+                ses.update(e); // Valid update.
+
+                ses.save(new Entity(2, "name-2")); // Valid insert.
+
+                ses.delete(ses.load(Entity2.class, 0)); // Valid delete.
+
+                Entity2 e2 = (Entity2)ses.load(Entity2.class, 1);
+
+                e2.setName("name-2");  // Invalid update, not-unique name.
+
+                ses.update(e2);
+
+                tx.commit();
+
+                fail("Commit must fail.");
+            }
+            catch (ConstraintViolationException e) {
+                log.info("Expected exception: " + e);
+
+                tx.rollback();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName1, 0, 2, 100);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName1, 0, 2, 100);
+
+            assertEntityCache(ENTITY2_NAME, sesFactory2, idToName2, 100);
+            assertEntityCache(ENTITY2_NAME, sesFactory1, idToName2, 100);
+
+            ses = sesFactory2.openSession();
+
+            try {
+                // Update, remove, insert in single transaction.
+
+                tx = ses.beginTransaction();
+
+                Entity e = (Entity)ses.load(Entity.class, 1);
+
+                e.setName("name-1-changed1");
+
+                ses.update(e);
+
+                idToName1.put(1, e.getName());
+
+                ses.save(new Entity(2, "name-2"));
+
+                idToName1.put(2, "name-2");
+
+                ses.delete(ses.load(Entity2.class, 0));
+
+                idToName2.remove(0);
+
+                Entity2 e2 = (Entity2)ses.load(Entity2.class, 1);
+
+                e2.setName("name-e2-2-changed");
+
+                ses.update(e2);
+
+                idToName2.put(1, e2.getName());
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName1, 0, 100);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName1, 0, 100);
+
+            assertEntityCache(ENTITY2_NAME, sesFactory2, idToName2, 0, 100);
+            assertEntityCache(ENTITY2_NAME, sesFactory1, idToName2, 0, 100);
+        }
+        finally {
+            cleanup();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testVersionedEntity() throws Exception {
+        for (AccessType accessType : accessTypes())
+            testVersionedEntity(accessType);
+    }
+
+    /**
+     * @param accessType Cache access type.
+     * @throws Exception If failed.
+     */
+    private void testVersionedEntity(AccessType accessType) throws Exception {
+        createSessionFactories(accessType);
+
+        try {
+            Session ses = sesFactory1.openSession();
+
+            VersionedEntity e0 = new VersionedEntity(0);
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                ses.save(e0);
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            ses = sesFactory1.openSession();
+
+            long ver;
+
+            try {
+                ver = ((VersionedEntity)ses.load(VersionedEntity.class, 0)).getVersion();
+            }
+            finally {
+                ses.close();
+            }
+
+            SecondLevelCacheStatistics stats1 =
+                sesFactory1.getStatistics().getSecondLevelCacheStatistics(VERSIONED_ENTITY_NAME);
+            SecondLevelCacheStatistics stats2 =
+                sesFactory2.getStatistics().getSecondLevelCacheStatistics(VERSIONED_ENTITY_NAME);
+
+            assertEquals(1, stats1.getElementCountInMemory());
+            assertEquals(1, stats2.getElementCountInMemory());
+
+            ses = sesFactory2.openSession();
+
+            try {
+                assertEquals(ver, ((VersionedEntity)ses.load(VersionedEntity.class, 0)).getVersion());
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEquals(1, stats2.getElementCountInMemory());
+            assertEquals(1, stats2.getHitCount());
+
+            if (accessType == AccessType.READ_ONLY)
+                return;
+
+            e0.setVersion(ver - 1);
+
+            ses = sesFactory1.openSession();
+
+            Transaction tx = ses.beginTransaction();
+
+            try {
+                ses.update(e0);
+
+                tx.commit();
+
+                fail("Commit must fail.");
+            }
+            catch (StaleObjectStateException e) {
+                log.info("Expected exception: " + e);
+            }
+            finally {
+                tx.rollback();
+
+                ses.close();
+            }
+
+            sesFactory1.getStatistics().clear();
+
+            stats1 = sesFactory1.getStatistics().getSecondLevelCacheStatistics(VERSIONED_ENTITY_NAME);
+
+            ses = sesFactory1.openSession();
+
+            try {
+                assertEquals(ver, ((VersionedEntity)ses.load(VersionedEntity.class, 0)).getVersion());
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEquals(1, stats1.getElementCountInMemory());
+            assertEquals(1, stats1.getHitCount());
+            assertEquals(1, stats2.getElementCountInMemory());
+            assertEquals(1, stats2.getHitCount());
+        }
+        finally {
+            cleanup();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNaturalIdCache() throws Exception {
+        for (AccessType accessType : accessTypes())
+            testNaturalIdCache(accessType);
+    }
+
+    /**
+     * @param accessType Cache access type.
+     * @throws Exception If failed.
+     */
+    private void testNaturalIdCache(AccessType accessType) throws Exception {
+        createSessionFactories(accessType);
+
+        Map<String, Integer> nameToId = new HashMap<>();
+
+        try {
+            Session ses = sesFactory1.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                for (int i = 0; i < 3; i++) {
+                    String name = "name-" + i;
+
+                    ses.save(new Entity(i, name));
+
+                    nameToId.put(name, i);
+                }
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            ses = sesFactory1.openSession();
+
+            try {
+                for (Map.Entry<String, Integer> e : nameToId.entrySet())
+                    ((Entity)ses.bySimpleNaturalId(Entity.class).load(e.getKey())).getId();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertNaturalIdCache(sesFactory2, nameToId, "name-100");
+            assertNaturalIdCache(sesFactory1, nameToId, "name-100");
+
+            if (accessType == AccessType.READ_ONLY)
+                return;
+
+            // Update naturalId.
+
+            ses = sesFactory1.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                Entity e1 = (Entity)ses.load(Entity.class, 1);
+
+                nameToId.remove(e1.getName());
+
+                e1.setName("name-1-changed1");
+
+                nameToId.put(e1.getName(), e1.getId());
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertNaturalIdCache(sesFactory2, nameToId, "name-1");
+            assertNaturalIdCache(sesFactory1, nameToId, "name-1");
+
+            // Update entity using another SessionFactory.
+
+            ses = sesFactory2.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                Entity e1 = (Entity)ses.load(Entity.class, 1);
+
+                nameToId.remove(e1.getName());
+
+                e1.setName("name-1-changed2");
+
+                nameToId.put(e1.getName(), e1.getId());
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertNaturalIdCache(sesFactory2, nameToId, "name-1-changed1");
+            assertNaturalIdCache(sesFactory1, nameToId, "name-1-changed1");
+
+            // Try invalid NaturalId update.
+
+            ses = sesFactory1.openSession();
+
+            Transaction tx = ses.beginTransaction();
+
+            try {
+                Entity e1 = (Entity)ses.load(Entity.class, 1);
+
+                e1.setName("name-0"); // Invalid update (duplicated name).
+
+                tx.commit();
+
+                fail("Commit must fail.");
+            }
+            catch (ConstraintViolationException e) {
+                log.info("Expected exception: " + e);
+
+                tx.rollback();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertNaturalIdCache(sesFactory2, nameToId);
+            assertNaturalIdCache(sesFactory1, nameToId);
+
+            // Delete entity.
+
+            ses = sesFactory2.openSession();
+
+            try {
+                tx = ses.beginTransaction();
+
+                Entity e2 = (Entity)ses.load(Entity.class, 2);
+
+                ses.delete(e2);
+
+                nameToId.remove(e2.getName());
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertNaturalIdCache(sesFactory2, nameToId, "name-2");
+            assertNaturalIdCache(sesFactory1, nameToId, "name-2");
+        }
+        finally {
+            cleanup();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testEntityCacheTransactionFails() throws Exception {
+        for (AccessType accessType : accessTypes())
+            testEntityCacheTransactionFails(accessType);
+    }
+
+    /**
+     * @param accessType Cache access type.
+     * @throws Exception If failed.
+     */
+    private void testEntityCacheTransactionFails(AccessType accessType) throws Exception {
+        createSessionFactories(accessType);
+
+        Map<Integer, String> idToName = new HashMap<>();
+
+        try {
+            Session ses = sesFactory1.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                for (int i = 0; i < 3; i++) {
+                    String name = "name-" + i;
+
+                    ses.save(new Entity(i, name));
+
+                    idToName.put(i, name);
+                }
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName, 100);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName, 100);
+
+            ses = sesFactory1.openSession();
+
+            Transaction tx = ses.beginTransaction();
+
+            try {
+                ses.save(new Entity(3, "name-3")); // Valid insert.
+
+                ses.save(new Entity(0, "name-0")); // Invalid insert (duplicated ID).
+
+                tx.commit();
+
+                fail("Commit must fail.");
+            }
+            catch (ConstraintViolationException e) {
+                log.info("Expected exception: " + e);
+
+                tx.rollback();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName, 3);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName, 3);
+
+            if (accessType == AccessType.READ_ONLY)
+                return;
+
+            ses = sesFactory1.openSession();
+
+            tx = ses.beginTransaction();
+
+            try {
+                Entity e0 = (Entity)ses.load(Entity.class, 0);
+                Entity e1 = (Entity)ses.load(Entity.class, 1);
+
+                e0.setName("name-10"); // Valid update.
+                e1.setName("name-2"); // Invalid update (violates unique constraint).
+
+                ses.update(e0);
+                ses.update(e1);
+
+                tx.commit();
+
+                fail("Commit must fail.");
+            }
+            catch (ConstraintViolationException e) {
+                log.info("Expected exception: " + e);
+
+                tx.rollback();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName);
+
+            ses = sesFactory1.openSession();
+
+            try {
+                // Create parent entity referencing Entity with ID = 0.
+
+                tx = ses.beginTransaction();
+
+                ses.save(new ParentEntity(0, (Entity) ses.load(Entity.class, 0)));
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            ses = sesFactory1.openSession();
+
+            tx = ses.beginTransaction();
+
+            try {
+                ses.save(new Entity(3, "name-3")); // Valid insert.
+
+                Entity e1 = (Entity)ses.load(Entity.class, 1);
+
+                e1.setName("name-10"); // Valid update.
+
+                ses.delete(ses.load(Entity.class, 0)); // Invalid delete (there is a parent entity referencing it).
+
+                tx.commit();
+
+                fail("Commit must fail.");
+            }
+            catch (ConstraintViolationException e) {
+                log.info("Expected exception: " + e);
+
+                tx.rollback();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName, 3);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName, 3);
+
+            ses = sesFactory1.openSession();
+
+            tx = ses.beginTransaction();
+
+            try {
+                ses.delete(ses.load(Entity.class, 1)); // Valid delete.
+
+                idToName.remove(1);
+
+                ses.delete(ses.load(Entity.class, 0)); // Invalid delete (there is a parent entity referencing it).
+
+                tx.commit();
+
+                fail("Commit must fail.");
+            }
+            catch (ConstraintViolationException e) {
+                log.info("Expected exception: " + e);
+
+                tx.rollback();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName);
+        }
+        finally {
+            cleanup();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testQueryCache() throws Exception {
+        for (AccessType accessType : accessTypes())
+            testQueryCache(accessType);
+    }
+
+    /**
+     * @param accessType Cache access type.
+     * @throws Exception If failed.
+     */
+    private void testQueryCache(AccessType accessType) throws Exception {
+        createSessionFactories(accessType);
+
+        try {
+            Session ses = sesFactory1.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                for (int i = 0; i < 5; i++)
+                    ses.save(new Entity(i, "name-" + i));
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            // Run some queries.
+
+            ses = sesFactory1.openSession();
+
+            try {
+                Query qry1 = ses.createQuery("from " + ENTITY_NAME + " where id > 2");
+
+                qry1.setCacheable(true);
+
+                assertEquals(2, qry1.list().size());
+
+                Query qry2 = ses.createQuery("from " + ENTITY_NAME + " where name = 'name-0'");
+
+                qry2.setCacheable(true);
+
+                assertEquals(1, qry2.list().size());
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEquals(0, sesFactory1.getStatistics().getQueryCacheHitCount());
+            assertEquals(2, sesFactory1.getStatistics().getQueryCacheMissCount());
+            assertEquals(2, sesFactory1.getStatistics().getQueryCachePutCount());
+
+            // Run queries using another SessionFactory.
+
+            ses = sesFactory2.openSession();
+
+            try {
+                Query qry1 = ses.createQuery("from " + ENTITY_NAME + " where id > 2");
+
+                qry1.setCacheable(true);
+
+                assertEquals(2, qry1.list().size());
+
+                Query qry2 = ses.createQuery("from " + ENTITY_NAME + " where name = 'name-0'");
+
+                qry2.setCacheable(true);
+
+                assertEquals(1, qry2.list().size());
+
+                Query qry3 = ses.createQuery("from " + ENTITY_NAME + " where id > 1");
+
+                qry3.setCacheable(true);
+
+                assertEquals(3, qry3.list().size());
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEquals(2, sesFactory2.getStatistics().getQueryCacheHitCount());
+            assertEquals(1, sesFactory2.getStatistics().getQueryCacheMissCount());
+            assertEquals(1, sesFactory2.getStatistics().getQueryCachePutCount());
+
+            // Update entity, it should invalidate query cache.
+
+            ses = sesFactory1.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                ses.save(new Entity(5, "name-5"));
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            // Run queries.
+
+            ses = sesFactory1.openSession();
+
+            sesFactory1.getStatistics().clear();
+
+            try {
+                Query qry1 = ses.createQuery("from " + ENTITY_NAME + " where id > 2");
+
+                qry1.setCacheable(true);
+
+                assertEquals(3, qry1.list().size());
+
+                Query qry2 = ses.createQuery("from " + ENTITY_NAME + " where name = 'name-0'");
+
+                qry2.setCacheable(true);
+
+                assertEquals(1, qry2.list().size());
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEquals(0, sesFactory1.getStatistics().getQueryCacheHitCount());
+            assertEquals(2, sesFactory1.getStatistics().getQueryCacheMissCount());
+            assertEquals(2, sesFactory1.getStatistics().getQueryCachePutCount());
+
+            // Clear query cache using another SessionFactory.
+
+            sesFactory2.getCache().evictDefaultQueryRegion();
+
+            ses = sesFactory1.openSession();
+
+            // Run queries again.
+
+            sesFactory1.getStatistics().clear();
+
+            try {
+                Query qry1 = ses.createQuery("from " + ENTITY_NAME + " where id > 2");
+
+                qry1.setCacheable(true);
+
+                assertEquals(3, qry1.list().size());
+
+                Query qry2 = ses.createQuery("from " + ENTITY_NAME + " where name = 'name-0'");
+
+                qry2.setCacheable(true);
+
+                assertEquals(1, qry2.list().size());
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEquals(0, sesFactory1.getStatistics().getQueryCacheHitCount());
+            assertEquals(2, sesFactory1.getStatistics().getQueryCacheMissCount());
+            assertEquals(2, sesFactory1.getStatistics().getQueryCachePutCount());
+        }
+        finally {
+            cleanup();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testRegionClear() throws Exception {
+        for (AccessType accessType : accessTypes())
+            testRegionClear(accessType);
+    }
+
+    /**
+     * @param accessType Cache access type.
+     * @throws Exception If failed.
+     */
+    private void testRegionClear(AccessType accessType) throws Exception {
+        createSessionFactories(accessType);
+
+        try {
+            final int ENTITY_CNT = 100;
+
+            Session ses = sesFactory1.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                for (int i = 0; i < ENTITY_CNT; i++) {
+                    Entity e = new Entity(i, "name-" + i);
+
+                    Collection<ChildEntity> children = new ArrayList<>();
+
+                    for (int j = 0; j < 3; j++)
+                        children.add(new ChildEntity());
+
+                    e.setChildren(children);
+
+                    ses.save(e);
+                }
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            loadEntities(sesFactory2, ENTITY_CNT);
+
+            SecondLevelCacheStatistics stats1 = sesFactory1.getStatistics().getSecondLevelCacheStatistics(ENTITY_NAME);
+            SecondLevelCacheStatistics stats2 = sesFactory2.getStatistics().getSecondLevelCacheStatistics(ENTITY_NAME);
+
+            NaturalIdCacheStatistics idStats1 =
+                sesFactory1.getStatistics().getNaturalIdCacheStatistics(NATURAL_ID_REGION);
+            NaturalIdCacheStatistics idStats2 =
+                sesFactory2.getStatistics().getNaturalIdCacheStatistics(NATURAL_ID_REGION);
+
+            SecondLevelCacheStatistics colStats1 =
+                sesFactory1.getStatistics().getSecondLevelCacheStatistics(CHILD_COLLECTION_REGION);
+            SecondLevelCacheStatistics colStats2 =
+                sesFactory2.getStatistics().getSecondLevelCacheStatistics(CHILD_COLLECTION_REGION);
+
+            assertEquals(ENTITY_CNT, stats1.getElementCountInMemory());
+            assertEquals(ENTITY_CNT, stats2.getElementCountInMemory());
+
+            assertEquals(ENTITY_CNT, idStats1.getElementCountInMemory());
+            assertEquals(ENTITY_CNT, idStats2.getElementCountInMemory());
+
+            assertEquals(ENTITY_CNT, colStats1.getElementCountInMemory());
+            assertEquals(ENTITY_CNT, colStats2.getElementCountInMemory());
+
+            // Test cache is cleared after update query.
+
+            ses = sesFactory1.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                ses.createQuery("delete from " + ENTITY_NAME + " where name='no such name'").executeUpdate();
+
+                ses.createQuery("delete from " + ChildEntity.class.getName() + " where id=-1").executeUpdate();
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEquals(0, stats1.getElementCountInMemory());
+            assertEquals(0, stats2.getElementCountInMemory());
+
+            assertEquals(0, idStats1.getElementCountInMemory());
+            assertEquals(0, idStats2.getElementCountInMemory());
+
+            assertEquals(0, colStats1.getElementCountInMemory());
+            assertEquals(0, colStats2.getElementCountInMemory());
+
+            // Load some data in cache.
+
+            loadEntities(sesFactory1, 10);
+
+            assertEquals(10, stats1.getElementCountInMemory());
+            assertEquals(10, stats2.getElementCountInMemory());
+            assertEquals(10, idStats1.getElementCountInMemory());
+            assertEquals(10, idStats2.getElementCountInMemory());
+
+            // Test evictAll method.
+
+            sesFactory2.getCache().evictEntityRegion(ENTITY_NAME);
+
+            assertEquals(0, stats1.getElementCountInMemory());
+            assertEquals(0, stats2.getElementCountInMemory());
+
+            sesFactory2.getCache().evictNaturalIdRegion(ENTITY_NAME);
+
+            assertEquals(0, idStats1.getElementCountInMemory());
+            assertEquals(0, idStats2.getElementCountInMemory());
+
+            sesFactory2.getCache().evictCollectionRegion(CHILD_COLLECTION_REGION);
+
+            assertEquals(0, colStats1.getElementCountInMemory());
+            assertEquals(0, colStats2.getElementCountInMemory());
+        }
+        finally {
+            cleanup();
+        }
+    }
+
+    /**
+     * @param sesFactory Session factory.
+     * @param nameToId Name-ID mapping.
+     * @param absentNames Absent entities' names.
+     */
+    private void assertNaturalIdCache(SessionFactory sesFactory, Map<String, Integer> nameToId, String... absentNames) {
+        sesFactory.getStatistics().clear();
+
+        NaturalIdCacheStatistics stats =
+            sesFactory.getStatistics().getNaturalIdCacheStatistics(NATURAL_ID_REGION);
+
+        long hitBefore = stats.getHitCount();
+
+        long missBefore = stats.getMissCount();
+
+        final Session ses = sesFactory.openSession();
+
+        try {
+            for (Map.Entry<String, Integer> e : nameToId.entrySet())
+                assertEquals((int)e.getValue(), ((Entity)ses.bySimpleNaturalId(Entity.class).load(e.getKey())).getId());
+
+            for (String name : absentNames)
+                assertNull((ses.bySimpleNaturalId(Entity.class).load(name)));
+
+            assertEquals(nameToId.size() + hitBefore, stats.getHitCount());
+
+            assertEquals(absentNames.length + missBefore, stats.getMissCount());
+        }
+        finally {
+            ses.close();
+        }
+    }
+
+    /**
+     * @param sesFactory Session factory.
+     * @param idToChildCnt Number of children per entity.
+     * @param expHit Expected cache hits.
+     * @param expMiss Expected cache misses.
+     */
+    @SuppressWarnings("unchecked")
+    private void assertCollectionCache(SessionFactory sesFactory, Map<Integer, Integer> idToChildCnt, int expHit,
+        int expMiss) {
+        sesFactory.getStatistics().clear();
+
+        Session ses = sesFactory.openSession();
+
+        try {
+            for(Map.Entry<Integer, Integer> e : idToChildCnt.entrySet()) {
+                Entity entity = (Entity)ses.load(Entity.class, e.getKey());
+
+                assertEquals((int)e.getValue(), entity.getChildren().size());
+            }
+        }
+        finally {
+            ses.close();
+        }
+
+        SecondLevelCacheStatistics stats =
+            sesFactory.getStatistics().getSecondLevelCacheStatistics(CHILD_COLLECTION_REGION);
+
+        assertEquals(expHit, stats.getHitCount());
+
+        assertEquals(expMiss, stats.getMissCount());
+    }
+
+    /**
+     * @param sesFactory Session factory.
+     * @param cnt Number of entities to load.
+     */
+    private void loadEntities(SessionFactory sesFactory, int cnt) {
+        Session ses = sesFactory.openSession();
+
+        try {
+            for (int i = 0; i < cnt; i++) {
+                Entity e = (Entity)ses.load(Entity.class, i);
+
+                assertEquals("name-" + i, e.getName());
+
+                assertFalse(e.getChildren().isEmpty());
+
+                ses.bySimpleNaturalId(Entity.class).load(e.getName());
+            }
+        }
+        finally {
+            ses.close();
+        }
+    }
+
+    /**
+     * @param entityName Entity name.
+     * @param sesFactory Session factory.
+     * @param idToName ID to name mapping.
+     * @param absentIds Absent entities' IDs.
+     */
+    private void assertEntityCache(String entityName, SessionFactory sesFactory, Map<Integer, String> idToName,
+        Integer... absentIds) {
+        assert entityName.equals(ENTITY_NAME) || entityName.equals(ENTITY2_NAME) : entityName;
+
+        sesFactory.getStatistics().clear();
+
+        final Session ses = sesFactory.openSession();
+
+        final boolean entity1 = entityName.equals(ENTITY_NAME);
+
+        try {
+            if (entity1) {
+                for (Map.Entry<Integer, String> e : idToName.entrySet())
+                    assertEquals(e.getValue(), ((Entity)ses.load(Entity.class, e.getKey())).getName());
+            }
+            else {
+                for (Map.Entry<Integer, String> e : idToName.entrySet())
+                    assertEquals(e.getValue(), ((Entity2)ses.load(Entity2.class, e.getKey())).getName());
+            }
+
+            for (final int id : absentIds) {
+                GridTestUtils.assertThrows(log, new Callable<Void>() {
+                    @Override public Void call() throws Exception {
+                        if (entity1)
+                            ((Entity)ses.load(Entity.class, id)).getName();
+                        else
+                            ((Entity2)ses.load(Entity2.class, id)).getName();
+
+                        return null;
+                    }
+                }, ObjectNotFoundException.class, null);
+            }
+
+            SecondLevelCacheStatistics stats = sesFactory.getStatistics().getSecondLevelCacheStatistics(entityName);
+
+            assertEquals(idToName.size(), stats.getHitCount());
+
+            assertEquals(absentIds.length, stats.getMissCount());
+        }
+        finally {
+            ses.close();
+        }
+    }
+
+    /**
+     * Creates session factories.
+     *
+     * @param accessType Cache access type.
+     */
+    private void createSessionFactories(AccessType accessType) {
+        sesFactory1 = startHibernate(accessType, getTestIgniteInstanceName(0));
+
+        sesFactory2 = startHibernate(accessType, getTestIgniteInstanceName(1));
+    }
+
+    /**
+     * Starts Hibernate.
+     *
+     * @param accessType Cache access type.
+     * @param igniteInstanceName Ignite instance name.
+     * @return Session factory.
+     */
+    private SessionFactory startHibernate(AccessType accessType, String igniteInstanceName) {
+        Configuration cfg = hibernateConfiguration(accessType, igniteInstanceName);
+
+        ServiceRegistryBuilder builder = registryBuilder();
+
+        builder.applySetting("hibernate.show_sql", false);
+
+        return cfg.buildSessionFactory(builder.buildServiceRegistry());
+    }
+
+    /**
+     * Closes session factories and clears data from caches.
+     *
+     * @throws Exception If failed.
+     */
+    private void cleanup() throws Exception {
+        if (sesFactory1 != null)
+            sesFactory1.close();
+
+        sesFactory1 = null;
+
+        if (sesFactory2 != null)
+            sesFactory2.close();
+
+        sesFactory2 = null;
+
+        for (IgniteCacheProxy<?, ?> cache : ((IgniteKernal)grid(0)).caches())
+            cache.clear();
+    }
+
+    /**
+     * @param igniteInstanceName Node name.
+     * @param dfltAccessType Default cache access type.
+     * @return Properties map.
+     */
+    static Map<String, String> hibernateProperties(String igniteInstanceName, String dfltAccessType) {
+        Map<String, String> map = new HashMap<>();
+
+        map.put(HBM2DDL_AUTO, "create");
+        map.put(GENERATE_STATISTICS, "true");
+        map.put(USE_SECOND_LEVEL_CACHE, "true");
+        map.put(USE_QUERY_CACHE, "true");
+        map.put(CACHE_REGION_FACTORY, HibernateRegionFactory.class.getName());
+        map.put(RELEASE_CONNECTIONS, "on_close");
+        map.put(IGNITE_INSTANCE_NAME_PROPERTY, igniteInstanceName);
+        map.put(DFLT_ACCESS_TYPE_PROPERTY, dfltAccessType);
+
+        return map;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalSelfTest.java b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalSelfTest.java
new file mode 100644
index 0000000..deca893
--- /dev/null
+++ b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalSelfTest.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import java.util.Collections;
+import javax.cache.configuration.Factory;
+import javax.transaction.Synchronization;
+import javax.transaction.TransactionManager;
+import javax.transaction.UserTransaction;
+import org.apache.commons.dbcp.managed.BasicManagedDataSource;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.h2.jdbcx.JdbcDataSource;
+import org.hibernate.cache.spi.access.AccessType;
+import org.hibernate.engine.transaction.internal.jta.JtaTransactionFactory;
+import org.hibernate.engine.transaction.spi.TransactionFactory;
+import org.hibernate.service.ServiceRegistryBuilder;
+import org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl;
+import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
+import org.hibernate.service.jta.platform.internal.AbstractJtaPlatform;
+import org.hibernate.service.jta.platform.spi.JtaPlatform;
+import org.jetbrains.annotations.Nullable;
+import org.objectweb.jotm.Jotm;
+
+/**
+ *
+ * Tests Hibernate L2 cache with TRANSACTIONAL access mode (Hibernate and Cache are configured
+ * to used the same TransactionManager).
+ */
+public class HibernateL2CacheTransactionalSelfTest extends HibernateL2CacheSelfTest {
+    /** */
+    private static Jotm jotm;
+
+    /**
+     */
+    private static class TestJtaPlatform extends AbstractJtaPlatform {
+        /** {@inheritDoc} */
+        @Override protected TransactionManager locateTransactionManager() {
+            return jotm.getTransactionManager();
+        }
+
+        /** {@inheritDoc} */
+        @Override protected UserTransaction locateUserTransaction() {
+            return jotm.getUserTransaction();
+        }
+    }
+
+    /**
+     */
+    @SuppressWarnings("PublicInnerClass")
+    public static class TestTmFactory implements Factory<TransactionManager> {
+        /** */
+        private static final long serialVersionUID = 0;
+
+        /** {@inheritDoc} */
+        @Override public TransactionManager create() {
+            return jotm.getTransactionManager();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        jotm = new Jotm(true, false);
+
+        super.beforeTestsStarted();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        super.afterTestsStopped();
+
+        if (jotm != null)
+            jotm.stop();
+
+        jotm = null;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        cfg.getTransactionConfiguration().setTxManagerFactory(new TestTmFactory());
+        cfg.getTransactionConfiguration().setUseJtaSynchronization(useJtaSynchronization());
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheConfiguration transactionalRegionConfiguration(String regionName) {
+        CacheConfiguration cfg = super.transactionalRegionConfiguration(regionName);
+
+        cfg.setNearConfiguration(null);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override protected ServiceRegistryBuilder registryBuilder() {
+        ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
+
+        DatasourceConnectionProviderImpl connProvider = new DatasourceConnectionProviderImpl();
+
+        BasicManagedDataSource dataSrc = new BasicManagedDataSource(); // JTA-aware data source.
+
+        dataSrc.setTransactionManager(jotm.getTransactionManager());
+
+        dataSrc.setDefaultAutoCommit(false);
+
+        JdbcDataSource h2DataSrc = new JdbcDataSource();
+
+        h2DataSrc.setURL(CONNECTION_URL);
+
+        dataSrc.setXaDataSourceInstance(h2DataSrc);
+
+        connProvider.setDataSource(dataSrc);
+
+        connProvider.configure(Collections.emptyMap());
+
+        builder.addService(ConnectionProvider.class, connProvider);
+
+        builder.addService(JtaPlatform.class, new TestJtaPlatform());
+
+        builder.addService(TransactionFactory.class, new JtaTransactionFactory());
+
+        return builder;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected AccessType[] accessTypes() {
+        return new AccessType[]{AccessType.TRANSACTIONAL};
+    }
+
+    /**
+     * @return Whether to use {@link Synchronization}.
+     */
+    protected boolean useJtaSynchronization() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalUseSyncSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalUseSyncSelfTest.java b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalUseSyncSelfTest.java
new file mode 100644
index 0000000..44899f9
--- /dev/null
+++ b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalUseSyncSelfTest.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import javax.transaction.Synchronization;
+
+/**
+ * Tests Hibernate L2 cache with TRANSACTIONAL access mode and {@link Synchronization}
+ * instead of XA resource.
+ */
+public class HibernateL2CacheTransactionalUseSyncSelfTest extends HibernateL2CacheTransactionalSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean useJtaSynchronization() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreNodeRestartTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreNodeRestartTest.java b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreNodeRestartTest.java
new file mode 100644
index 0000000..d5496af
--- /dev/null
+++ b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreNodeRestartTest.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.store.hibernate;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.store.CacheStore;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.integration.IgniteCacheStoreNodeRestartAbstractTest;
+
+public class CacheHibernateBlobStoreNodeRestartTest extends IgniteCacheStoreNodeRestartAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected CacheStore getStore() {
+        return new CacheHibernateBlobStore();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return CacheMode.PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return CacheAtomicityMode.ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return null;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreSelfTest.java b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreSelfTest.java
new file mode 100644
index 0000000..77025a1
--- /dev/null
+++ b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreSelfTest.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.store.hibernate;
+
+import java.io.File;
+import java.net.URL;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.junits.cache.GridAbstractCacheStoreSelfTest;
+import org.hibernate.FlushMode;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+
+/**
+ * Cache store test.
+ */
+public class CacheHibernateBlobStoreSelfTest extends
+    GridAbstractCacheStoreSelfTest<CacheHibernateBlobStore<Object, Object>> {
+    /**
+     * @throws Exception If failed.
+     */
+    public CacheHibernateBlobStoreSelfTest() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        Session s = store.session(null);
+
+        if (s == null)
+            return;
+
+        try {
+            s.createQuery("delete from " + CacheHibernateBlobStoreEntry.class.getSimpleName())
+                    .setFlushMode(FlushMode.ALWAYS).executeUpdate();
+
+            Transaction hTx = s.getTransaction();
+
+            if (hTx != null && hTx.isActive())
+                hTx.commit();
+        }
+        finally {
+            s.close();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheHibernateBlobStore<Object, Object> store() {
+        return new CacheHibernateBlobStore<>();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testConfigurationByUrl() throws Exception {
+        URL url = U.resolveIgniteUrl(CacheHibernateStoreFactorySelfTest.MODULE_PATH +
+            "/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml");
+
+        assert url != null;
+
+        store.setHibernateConfigurationPath(url.toString());
+
+        // Store will be implicitly initialized.
+        store.load("key");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testConfigurationByFile() throws Exception {
+        URL url = U.resolveIgniteUrl(CacheHibernateStoreFactorySelfTest.MODULE_PATH +
+                "/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml");
+
+        assert url != null;
+
+        File file = new File(url.toURI());
+
+        store.setHibernateConfigurationPath(file.getAbsolutePath());
+
+        // Store will be implicitly initialized.
+        store.load("key");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testConfigurationByResource() throws Exception {
+        store.setHibernateConfigurationPath("/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml");
+
+        // Store will be implicitly initialized.
+        store.load("key");
+    }
+
+    @Override public void testSimpleMultithreading() throws Exception {
+        fail("https://issues.apache.org/jira/browse/IGNITE-1757");
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreFactorySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreFactorySelfTest.java b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreFactorySelfTest.java
new file mode 100644
index 0000000..f6c8a2d
--- /dev/null
+++ b/modules/hibernate-4.2/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreFactorySelfTest.java
@@ -0,0 +1,288 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.store.hibernate;
+
+import java.io.Serializable;
+import java.sql.Connection;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.hibernate.Cache;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.SessionBuilder;
+import org.hibernate.SessionFactory;
+import org.hibernate.StatelessSession;
+import org.hibernate.StatelessSessionBuilder;
+import org.hibernate.TypeHelper;
+import org.hibernate.engine.spi.FilterDefinition;
+import org.hibernate.metadata.ClassMetadata;
+import org.hibernate.metadata.CollectionMetadata;
+import org.hibernate.stat.Statistics;
+
+/**
+ * Test for Cache jdbc blob store factory.
+ */
+public class CacheHibernateStoreFactorySelfTest extends GridCommonAbstractTest {
+    /** Cache name. */
+    private static final String CACHE_NAME = "test";
+
+    /** */
+    static final String MODULE_PATH = "modules/hibernate-4.2/";
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCacheConfiguration() throws Exception {
+        try (Ignite ignite1 = startGrid(0)) {
+            IgniteCache<Integer, String> cache1 = ignite1.getOrCreateCache(cacheConfiguration());
+
+            checkStore(cache1);
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testXmlConfiguration() throws Exception {
+        try (Ignite ignite = Ignition.start(MODULE_PATH + "/src/test/config/factory-cache.xml")) {
+            try(Ignite ignite1 = Ignition.start(MODULE_PATH + "/src/test/config/factory-cache1.xml")) {
+                checkStore(ignite.<Integer, String>cache(CACHE_NAME), DummySessionFactoryExt.class);
+
+                checkStore(ignite1.<Integer, String>cache(CACHE_NAME), DummySessionFactory.class);
+            }
+        }
+    }
+
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testIncorrectBeanConfiguration() throws Exception {
+        GridTestUtils.assertThrows(log, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                try(Ignite ignite =
+                    Ignition.start(MODULE_PATH + "/src/test/config/factory-incorrect-store-cache.xml")) {
+                    ignite.cache(CACHE_NAME).getConfiguration(CacheConfiguration.class).
+                            getCacheStoreFactory().create();
+                }
+                return null;
+            }
+        }, IgniteException.class, "Failed to load bean in application context");
+    }
+
+    /**
+     * @return Cache configuration with store.
+     */
+    private CacheConfiguration<Integer, String> cacheConfiguration() {
+        CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>();
+
+        CacheHibernateBlobStoreFactory<Integer, String> factory = new CacheHibernateBlobStoreFactory();
+
+        factory.setHibernateConfigurationPath("/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml");
+
+        cfg.setCacheStoreFactory(factory);
+
+        return cfg;
+    }
+
+    /**
+     * @param cache Ignite cache.
+     * @param dataSrcClass Data source class.
+     * @throws Exception If store parameters is not the same as in configuration xml.
+     */
+    private void checkStore(IgniteCache<Integer, String> cache, Class<?> dataSrcClass) throws Exception {
+        CacheHibernateBlobStore store = (CacheHibernateBlobStore)cache
+            .getConfiguration(CacheConfiguration.class).getCacheStoreFactory().create();
+
+        assertEquals(dataSrcClass,
+            GridTestUtils.getFieldValue(store, CacheHibernateBlobStore.class, "sesFactory").getClass());
+    }
+
+    /**
+     * @param cache Ignite cache.
+     * @throws Exception If store parameters is not the same as in configuration xml.
+     */
+    private void checkStore(IgniteCache<Integer, String> cache) throws Exception {
+        CacheHibernateBlobStore store = (CacheHibernateBlobStore)cache.getConfiguration(CacheConfiguration.class)
+            .getCacheStoreFactory().create();
+
+        assertEquals("/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml",
+            GridTestUtils.getFieldValue(store, CacheHibernateBlobStore.class, "hibernateCfgPath"));
+    }
+
+    /**
+     *
+     */
+    public static class DummySessionFactoryExt extends DummySessionFactory {
+        /** */
+        public DummySessionFactoryExt() {
+            // No-op.
+        }
+    }
+
+    /**
+     *
+     */
+    public static class DummySessionFactory implements SessionFactory {
+        /** {@inheritDoc} */
+        @Override public SessionFactoryOptions getSessionFactoryOptions() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public SessionBuilder withOptions() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Session openSession() throws HibernateException {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Session getCurrentSession() throws HibernateException {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public StatelessSessionBuilder withStatelessOptions() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public StatelessSession openStatelessSession() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public StatelessSession openStatelessSession(Connection conn) {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public ClassMetadata getClassMetadata(Class entityCls) {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public ClassMetadata getClassMetadata(String entityName) {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public CollectionMetadata getCollectionMetadata(String roleName) {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Map<String, ClassMetadata> getAllClassMetadata() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Map getAllCollectionMetadata() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Statistics getStatistics() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void close() throws HibernateException {
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean isClosed() {
+            return false;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Cache getCache() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void evict(Class persistentCls) throws HibernateException {
+        }
+
+        /** {@inheritDoc} */
+        @Override public void evict(Class persistentCls, Serializable id) throws HibernateException {
+        }
+
+        /** {@inheritDoc} */
+        @Override public void evictEntity(String entityName) throws HibernateException {
+        }
+
+        /** {@inheritDoc} */
+        @Override public void evictEntity(String entityName, Serializable id) throws HibernateException {
+        }
+
+        /** {@inheritDoc} */
+        @Override public void evictCollection(String roleName) throws HibernateException {
+        }
+
+        /** {@inheritDoc} */
+        @Override public void evictCollection(String roleName, Serializable id) throws HibernateException {
+        }
+
+        /** {@inheritDoc} */
+        @Override public void evictQueries(String cacheRegion) throws HibernateException {
+        }
+
+        /** {@inheritDoc} */
+        @Override public void evictQueries() throws HibernateException {
+        }
+
+        /** {@inheritDoc} */
+        @Override public Set getDefinedFilterNames() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public FilterDefinition getFilterDefinition(String filterName) throws HibernateException {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean containsFetchProfileDefinition(String name) {
+            return false;
+        }
+
+        /** {@inheritDoc} */
+        @Override public TypeHelper getTypeHelper() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Reference getReference() throws NamingException {
+            return null;
+        }
+    }
+}
\ No newline at end of file


[08/16] ignite git commit: ignite-1794 Refactored hibernate modules, switched to hibernate 5.1

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java
deleted file mode 100644
index ad5b191..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateEntityRegion.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.apache.ignite.Ignite;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.CacheDataDescription;
-import org.hibernate.cache.spi.EntityRegion;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
-import org.hibernate.cache.spi.access.SoftLock;
-
-/**
- * Implementation of {@link EntityRegion}. This region is used to store entity data.
- * <p>
- * L2 cache for entity can be enabled in the Hibernate configuration file:
- * <pre name="code" class="xml">
- * &lt;hibernate-configuration&gt;
- *     &lt;!-- Enable L2 cache. --&gt;
- *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
- *
- *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
- *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
- *
- *     &lt;!-- Specify entity. --&gt;
- *     &lt;mapping class="com.example.Entity"/&gt;
- *
- *     &lt;!-- Enable L2 cache with nonstrict-read-write access strategy for entity. --&gt;
- *     &lt;class-cache class="com.example.Entity" usage="nonstrict-read-write"/&gt;
- * &lt;/hibernate-configuration&gt;
- * </pre>
- * Also cache for entity can be enabled using annotations:
- * <pre name="code" class="java">
- * &#064;javax.persistence.Entity
- * &#064;javax.persistence.Cacheable
- * &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
- * public class Entity { ... }
- * </pre>
- */
-public class HibernateEntityRegion extends HibernateTransactionalDataRegion implements EntityRegion {
-    /**
-     * @param factory Region factory.
-     * @param name Region name.
-     * @param ignite Grid.
-     * @param cache Region cache,
-     * @param dataDesc Region data description.
-     */
-    public HibernateEntityRegion(HibernateRegionFactory factory, String name, Ignite ignite,
-        HibernateCacheProxy cache, CacheDataDescription dataDesc) {
-        super(factory, name, ignite, cache, dataDesc);
-    }
-
-    /** {@inheritDoc} */
-    @Override public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
-        return new AccessStrategy(createAccessStrategy(accessType));
-    }
-
-    /**
-     * Entity region access strategy.
-     */
-    private class AccessStrategy extends HibernateAbstractRegionAccessStrategy
-        implements EntityRegionAccessStrategy {
-        /**
-         * @param stgy Access strategy implementation.
-         */
-        private AccessStrategy(HibernateAccessStrategyAdapter stgy) {
-            super(stgy);
-        }
-
-        /** {@inheritDoc} */
-        @Override public EntityRegion getRegion() {
-            return HibernateEntityRegion.this;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean insert(Object key, Object val, Object ver) throws CacheException {
-            return stgy.insert(key, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean afterInsert(Object key, Object val, Object ver) throws CacheException {
-            return stgy.afterInsert(key, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean update(Object key, Object val, Object currVer, Object previousVer)
-            throws CacheException {
-            return stgy.update(key, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean afterUpdate(Object key, Object val, Object currVer, Object previousVer, SoftLock lock)
-            throws CacheException {
-            return stgy.afterUpdate(key, val, lock);
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateGeneralDataRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateGeneralDataRegion.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateGeneralDataRegion.java
deleted file mode 100644
index 2f1a11d..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateGeneralDataRegion.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCheckedException;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.GeneralDataRegion;
-import org.hibernate.cache.spi.QueryResultsRegion;
-import org.hibernate.cache.spi.TimestampsRegion;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Implementation of {@link GeneralDataRegion}. This interface defines common contract for {@link QueryResultsRegion}
- * and {@link TimestampsRegion}.
- */
-public class HibernateGeneralDataRegion extends HibernateRegion implements GeneralDataRegion {
-    /**
-     * @param factory Region factory.
-     * @param name Region name.
-     * @param ignite Grid.
-     * @param cache Region cache.
-     */
-    public HibernateGeneralDataRegion(HibernateRegionFactory factory, String name,
-        Ignite ignite, HibernateCacheProxy cache) {
-        super(factory, name, ignite, cache);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object get(Object key) throws CacheException {
-        try {
-            return cache.get(key);
-        } catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void put(Object key, Object val) throws CacheException {
-        try {
-            cache.put(key, val);
-        } catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void evict(Object key) throws CacheException {
-        HibernateAccessStrategyAdapter.evict(ignite, cache, key);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void evictAll() throws CacheException {
-        HibernateAccessStrategyAdapter.evictAll(cache);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyTransformer.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyTransformer.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyTransformer.java
deleted file mode 100644
index ecad0b6..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyTransformer.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-/**
- * An interface for transforming hibernate keys to Ignite keys.
- */
-public interface HibernateKeyTransformer {
-    /**
-     * @param key Hibernate key.
-     */
-    public Object transform(Object key);
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
deleted file mode 100644
index 7de440e..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateKeyWrapper.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.apache.ignite.internal.util.typedef.internal.S;
-
-/**
- * Hibernate cache key wrapper.
- */
-public class HibernateKeyWrapper {
-    /** Key. */
-    private final Object key;
-
-    /** Entry. */
-    private final String entry;
-
-    /** */
-    private final String tenantId;
-
-    /**
-     * @param key Key.
-     * @param entry Entry.
-     * @param tenantId Tenant ID.
-     */
-    HibernateKeyWrapper(Object key, String entry, String tenantId) {
-        this.key = key;
-        this.entry = entry;
-        this.tenantId = tenantId;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o) return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        HibernateKeyWrapper that = (HibernateKeyWrapper) o;
-
-        return (key != null ? key.equals(that.key) : that.key == null) &&
-            (entry != null ? entry.equals(that.entry) : that.entry == null) &&
-            (tenantId != null ? tenantId.equals(that.tenantId) : that.tenantId == null);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int res = key != null ? key.hashCode() : 0;
-        res = 31 * res + (entry != null ? entry.hashCode() : 0);
-        res = 31 * res + (tenantId != null ? tenantId.hashCode() : 0);
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(HibernateKeyWrapper.class, this);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateNaturalIdRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateNaturalIdRegion.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateNaturalIdRegion.java
deleted file mode 100644
index 862a422..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateNaturalIdRegion.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.apache.ignite.Ignite;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.CacheDataDescription;
-import org.hibernate.cache.spi.NaturalIdRegion;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy;
-import org.hibernate.cache.spi.access.SoftLock;
-
-/**
- * Implementation of {@link NaturalIdRegion}. This region is used to store naturalId data.
- * <p>
- * L2 cache for entity naturalId and target cache region can be set using annotations:
- * <pre name="code" class="java">
- * &#064;javax.persistence.Entity
- * &#064;javax.persistence.Cacheable
- * &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
- * &#064;org.hibernate.annotations.NaturalIdCache
- * public class Entity {
- *     &#064;org.hibernate.annotations.NaturalId
- *     private String entityCode;
- *
- *     ...
- * }
- * </pre>
- */
-public class HibernateNaturalIdRegion extends HibernateTransactionalDataRegion implements NaturalIdRegion {
-    /**
-     * @param factory Region factory.
-     * @param name Region name.
-     * @param ignite Grid.
-     * @param cache Region cache,
-     * @param dataDesc Region data description.
-     */
-    public HibernateNaturalIdRegion(HibernateRegionFactory factory, String name,
-        Ignite ignite, HibernateCacheProxy cache, CacheDataDescription dataDesc) {
-        super(factory, name, ignite, cache, dataDesc);
-    }
-
-    /** {@inheritDoc} */
-    @Override public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
-        return new AccessStrategy(createAccessStrategy(accessType));
-    }
-
-    /**
-     * NaturalId region access strategy.
-     */
-    private class AccessStrategy extends HibernateAbstractRegionAccessStrategy implements
-        NaturalIdRegionAccessStrategy {
-        /**
-         * @param stgy Access strategy implementation.
-         */
-        private AccessStrategy(HibernateAccessStrategyAdapter stgy) {
-            super(stgy);
-        }
-
-        /** {@inheritDoc} */
-        @Override public NaturalIdRegion getRegion() {
-            return HibernateNaturalIdRegion.this;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean insert(Object key, Object val) throws CacheException {
-            return stgy.insert(key, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean afterInsert(Object key, Object val) throws CacheException {
-            return stgy.afterInsert(key, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean update(Object key, Object val) throws CacheException {
-            return stgy.update(key, val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean afterUpdate(Object key, Object val, SoftLock lock) throws CacheException {
-            return stgy.afterUpdate(key, val, lock);
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateNonStrictAccessStrategy.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateNonStrictAccessStrategy.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateNonStrictAccessStrategy.java
deleted file mode 100644
index a36d7e7..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateNonStrictAccessStrategy.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import java.util.Map;
-import java.util.Set;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.util.GridLeanMap;
-import org.apache.ignite.internal.util.GridLeanSet;
-import org.apache.ignite.internal.util.typedef.F;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cache.spi.access.SoftLock;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Implementation of {@link AccessType#NONSTRICT_READ_WRITE} cache access strategy.
- * <p>
- * Configuration of L2 cache and per-entity cache access strategy can be set in the
- * Hibernate configuration file:
- * <pre name="code" class="xml">
- * &lt;hibernate-configuration&gt;
- *     &lt;!-- Enable L2 cache. --&gt;
- *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
- *
- *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
- *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
- *
- *     &lt;!-- Specify entity. --&gt;
- *     &lt;mapping class="com.example.Entity"/&gt;
- *
- *     &lt;!-- Enable L2 cache with nonstrict-read-write access strategy for entity. --&gt;
- *     &lt;class-cache class="com.example.Entity" usage="nonstrict-read-write"/&gt;
- * &lt;/hibernate-configuration&gt;
- * </pre>
- * Also cache access strategy can be set using annotations:
- * <pre name="code" class="java">
- * &#064;javax.persistence.Entity
- * &#064;javax.persistence.Cacheable
- * &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
- * public class Entity { ... }
- * </pre>
- */
-public class HibernateNonStrictAccessStrategy extends HibernateAccessStrategyAdapter {
-    /** */
-    private final ThreadLocal<WriteContext> writeCtx;
-
-    /**
-     * @param ignite Grid.
-     * @param cache Cache.
-     * @param writeCtx Thread local instance used to track updates done during one Hibernate transaction.
-     */
-    protected HibernateNonStrictAccessStrategy(Ignite ignite, HibernateCacheProxy cache, ThreadLocal writeCtx) {
-        super(ignite, cache);
-
-        this.writeCtx = (ThreadLocal<WriteContext>)writeCtx;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override protected SoftLock lock(Object key) throws CacheException {
-        WriteContext ctx = writeCtx.get();
-
-        if (ctx == null)
-            writeCtx.set(ctx = new WriteContext());
-
-        ctx.locked(key);
-
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void unlock(Object key, SoftLock lock) throws CacheException {
-        try {
-            WriteContext ctx = writeCtx.get();
-
-            if (ctx != null && ctx.unlocked(key)) {
-                writeCtx.remove();
-
-                ctx.updateCache(cache);
-            }
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean update(Object key, Object val) throws CacheException {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean afterUpdate(Object key, Object val, SoftLock lock) throws CacheException {
-        WriteContext ctx = writeCtx.get();
-
-        if (ctx != null) {
-            ctx.updated(key, val);
-
-            unlock(key, lock);
-
-            return true;
-        }
-
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean insert(Object key, Object val) throws CacheException {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean afterInsert(Object key, Object val) throws CacheException {
-        try {
-            cache.put(key, val);
-
-            return true;
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void remove(Object key) throws CacheException {
-        WriteContext ctx = writeCtx.get();
-
-        if (ctx != null)
-            ctx.removed(key);
-    }
-
-    /**
-     * Information about updates done during single database transaction.
-     */
-    @SuppressWarnings("TypeMayBeWeakened")
-    private static class WriteContext {
-        /** */
-        private Map<Object, Object> updates;
-
-        /** */
-        private Set<Object> rmvs;
-
-        /** */
-        private Set<Object> locked = new GridLeanSet<>();
-
-        /**
-         * Marks key as locked.
-         *
-         * @param key Key.
-         */
-        void locked(Object key) {
-            locked.add(key);
-        }
-
-        /**
-         * Marks key as unlocked.
-         *
-         * @param key Key.
-         * @return {@code True} if last locked key was unlocked.
-         */
-        boolean unlocked(Object key) {
-            locked.remove(key);
-
-            return locked.isEmpty();
-        }
-
-        /**
-         * Marks key as updated.
-         *
-         * @param key Key.
-         * @param val Value.
-         */
-        void updated(Object key, Object val) {
-            if (updates == null)
-                updates = new GridLeanMap<>();
-
-            updates.put(key, val);
-        }
-
-        /**
-         * Marks key as removed.
-         *
-         * @param key Key.
-         */
-        void removed(Object key) {
-            if (rmvs == null)
-                rmvs = new GridLeanSet<>();
-
-            rmvs.add(key);
-        }
-
-        /**
-         * Updates cache.
-         *
-         * @param cache Cache.
-         * @throws IgniteCheckedException If failed.
-         */
-        void updateCache(HibernateCacheProxy cache) throws IgniteCheckedException {
-            if (!F.isEmpty(rmvs))
-                cache.removeAll(rmvs);
-
-            if (!F.isEmpty(updates))
-                cache.putAll(updates);
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateQueryResultsRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateQueryResultsRegion.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateQueryResultsRegion.java
deleted file mode 100644
index 0b9a43d..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateQueryResultsRegion.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.apache.ignite.Ignite;
-import org.hibernate.Query;
-import org.hibernate.cache.spi.QueryResultsRegion;
-
-/**
- * Implementation of {@link QueryResultsRegion}. This region is used to store query results.
- * <p>
- * Query results caching can be enabled in the Hibernate configuration file:
- * <pre name="code" class="xml">
- * &lt;hibernate-configuration&gt;
- *     &lt;!-- Enable L2 cache. --&gt;
- *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
- *
- *     &lt;!-- Enable query cache. --&gt;
- *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
-
- *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
- *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
- *
- *     &lt;!-- Specify entity. --&gt;
- *     &lt;mapping class="com.example.Entity"/&gt;
- *
- *     &lt;!-- Enable L2 cache with nonstrict-read-write access strategy for entity. --&gt;
- *     &lt;class-cache class="com.example.Entity" usage="nonstrict-read-write"/&gt;
- * &lt;/hibernate-configuration&gt;
- * </pre>
- * By default queries are not cached even after enabling query caching, to enable results caching for a particular
- * query, call {@link Query#setCacheable(boolean)}:
- * <pre name="code" class="java">
- *     Session ses = getSession();
- *
- *     Query qry = ses.createQuery("...");
- *
- *     qry.setCacheable(true); // Enable L2 cache for query.
- * </pre>
- * Note: the query cache does not cache the state of the actual entities in the cache, it caches only identifier
- * values. For this reason, the query cache should always be used in conjunction with
- * the second-level cache for those entities expected to be cached as part of a query result cache
- */
-public class HibernateQueryResultsRegion extends HibernateGeneralDataRegion implements QueryResultsRegion {
-    /**
-     * @param factory Region factory.
-     * @param name Region name.
-     * @param ignite Grid.
-     * @param cache Region cache.
-     */
-    public HibernateQueryResultsRegion(HibernateRegionFactory factory, String name,
-        Ignite ignite, HibernateCacheProxy cache) {
-        super(factory, name, ignite, cache);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadOnlyAccessStrategy.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadOnlyAccessStrategy.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadOnlyAccessStrategy.java
deleted file mode 100644
index cdef80e..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadOnlyAccessStrategy.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCheckedException;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cache.spi.access.SoftLock;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Implementation of {@link AccessType#READ_ONLY} cache access strategy.
- * <p>
- * Configuration of L2 cache and per-entity cache access strategy can be set in the
- * Hibernate configuration file:
- * <pre name="code" class="xml">
- * &lt;hibernate-configuration&gt;
- *     &lt;!-- Enable L2 cache. --&gt;
- *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
- *
- *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
- *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
- *
- *     &lt;!-- Specify entity. --&gt;
- *     &lt;mapping class="com.example.Entity"/&gt;
- *
- *     &lt;!-- Enable L2 cache with read-only access strategy for entity. --&gt;
- *     &lt;class-cache class="com.example.Entity" usage="read-only"/&gt;
- * &lt;/hibernate-configuration&gt;
- * </pre>
- * Also cache access strategy can be set using annotations:
- * <pre name="code" class="java">
- * &#064;javax.persistence.Entity
- * &#064;javax.persistence.Cacheable
- * &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
- * public class Entity { ... }
- * </pre>
-
- *
- */
-public class HibernateReadOnlyAccessStrategy extends HibernateAccessStrategyAdapter {
-    /**
-     * @param ignite Grid.
-     * @param cache Cache.
-     */
-    public HibernateReadOnlyAccessStrategy(Ignite ignite, HibernateCacheProxy cache) {
-        super(ignite, cache);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean insert(Object key, Object val) throws CacheException {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean afterInsert(Object key, Object val) throws CacheException {
-        try {
-            cache.put(key, val);
-
-            return true;
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override protected SoftLock lock(Object key) throws CacheException {
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void unlock(Object key, SoftLock lock) throws CacheException {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void remove(Object key) throws CacheException {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean update(Object key, Object val) throws CacheException {
-        throw new UnsupportedOperationException("Updates are not supported for read-only access strategy.");
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean afterUpdate(Object key, Object val, SoftLock lock) throws CacheException {
-        throw new UnsupportedOperationException("Updates are not supported for read-only access strategy.");
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadWriteAccessStrategy.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadWriteAccessStrategy.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadWriteAccessStrategy.java
deleted file mode 100644
index ae9bd71..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateReadWriteAccessStrategy.java
+++ /dev/null
@@ -1,328 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import java.util.Set;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
-import org.apache.ignite.internal.util.GridLeanSet;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cache.spi.access.SoftLock;
-
-import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
-import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
-
-/**
- * Implementation of {@link AccessType#READ_WRITE} cache access strategy.
- * <p>
- * Configuration of L2 cache and per-entity cache access strategy can be set in the
- * Hibernate configuration file:
- * <pre name="code" class="xml">
- * &lt;hibernate-configuration&gt;
- *     &lt;!-- Enable L2 cache. --&gt;
- *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
- *
- *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
- *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
- *
- *     &lt;!-- Specify entity. --&gt;
- *     &lt;mapping class="com.example.Entity"/&gt;
- *
- *     &lt;!-- Enable L2 cache with read-write access strategy for entity. --&gt;
- *     &lt;class-cache class="com.example.Entity" usage="read-write"/&gt;
- * &lt;/hibernate-configuration&gt;
- * </pre>
- * Also cache access strategy can be set using annotations:
- * <pre name="code" class="java">
- * &#064;javax.persistence.Entity
- * &#064;javax.persistence.Cacheable
- * &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
- * public class Entity { ... }
- * </pre>
- */
-public class HibernateReadWriteAccessStrategy extends HibernateAccessStrategyAdapter {
-    /** */
-    private final ThreadLocal<TxContext> txCtx;
-
-    /**
-     * @param ignite Grid.
-     * @param cache Cache.
-     * @param txCtx Thread local instance used to track updates done during one Hibernate transaction.
-     */
-    protected HibernateReadWriteAccessStrategy(Ignite ignite, HibernateCacheProxy cache, ThreadLocal txCtx) {
-        super(ignite, cache);
-
-        this.txCtx = (ThreadLocal<TxContext>)txCtx;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected Object get(Object key) throws CacheException {
-        boolean success = false;
-
-        try {
-            Object o = cache.get(key);
-
-            success = true;
-
-            return o;
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-        finally {
-            if (!success)
-                rollbackCurrentTx();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void putFromLoad(Object key, Object val) throws CacheException {
-        boolean success = false;
-
-        try {
-            cache.put(key, val);
-
-            success = true;
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-        finally {
-            if (!success)
-                rollbackCurrentTx();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected SoftLock lock(Object key) throws CacheException {
-        boolean success = false;
-
-        try {
-            TxContext ctx = txCtx.get();
-
-            if (ctx == null)
-                txCtx.set(ctx = new TxContext());
-
-            lockKey(key);
-
-            ctx.locked(key);
-
-            success = true;
-
-            return null;
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-        finally {
-            if (!success)
-                rollbackCurrentTx();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void unlock(Object key, SoftLock lock) throws CacheException {
-        boolean success = false;
-
-        try {
-            TxContext ctx = txCtx.get();
-
-            if (ctx != null)
-                unlock(ctx, key);
-
-            success = true;
-        }
-        catch (Exception e) {
-            throw new CacheException(e);
-        }
-        finally {
-            if (!success)
-                rollbackCurrentTx();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean update(Object key, Object val) throws CacheException {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean afterUpdate(Object key, Object val, SoftLock lock) throws CacheException {
-        boolean success = false;
-        boolean res = false;
-
-        try {
-            TxContext ctx = txCtx.get();
-
-            if (ctx != null) {
-                cache.put(key, val);
-
-                unlock(ctx, key);
-
-                res = true;
-            }
-
-            success = true;
-
-            return res;
-        }
-        catch (Exception e) {
-            throw new CacheException(e);
-        }
-        finally {
-            if (!success)
-                rollbackCurrentTx();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean insert(Object key, Object val) throws CacheException {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean afterInsert(Object key, Object val) throws CacheException {
-        boolean success = false;
-
-        try {
-            cache.put(key, val);
-
-            success = true;
-
-            return true;
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-        finally {
-            if (!success)
-                rollbackCurrentTx();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void remove(Object key) throws CacheException {
-        boolean success = false;
-
-        try {
-            TxContext ctx = txCtx.get();
-
-            if (ctx != null)
-                cache.remove(key);
-
-            success = true;
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-        finally {
-            if (!success)
-                rollbackCurrentTx();
-        }
-    }
-
-    /**
-     *
-     * @param ctx Transaction context.
-     * @param key Key.
-     * @throws CacheException If failed.
-     */
-    private void unlock(TxContext ctx, Object key) throws CacheException {
-        if (ctx.unlocked(key)) { // Finish transaction if last key is unlocked.
-            txCtx.remove();
-
-            GridNearTxLocal tx = cache.tx();
-
-            assert tx != null;
-
-            try {
-                tx.proxy().commit();
-            }
-            finally {
-                tx.proxy().close();
-            }
-
-            assert cache.tx() == null;
-        }
-    }
-
-    /**
-     * Roll backs current transaction.
-     */
-    private void rollbackCurrentTx() {
-        try {
-            TxContext ctx = txCtx.get();
-
-            if (ctx != null) {
-                txCtx.remove();
-
-                GridNearTxLocal tx = cache.tx();
-
-                if (tx != null)
-                    tx.proxy().rollback();
-            }
-        }
-        catch (IgniteException e) {
-            log.error("Failed to rollback cache transaction.", e);
-        }
-    }
-
-    /**
-     * @param key Key.
-     * @throws IgniteCheckedException If failed.
-     */
-    private void lockKey(Object key) throws IgniteCheckedException {
-        if (cache.tx() == null)
-            cache.txStart(PESSIMISTIC, REPEATABLE_READ);
-
-        cache.get(key); // Acquire distributed lock.
-    }
-
-    /**
-     * Information about updates done during single database transaction.
-     */
-    @SuppressWarnings("TypeMayBeWeakened")
-    private static class TxContext {
-        /** */
-        private Set<Object> locked = new GridLeanSet<>();
-
-        /**
-         * Marks key as locked.
-         *
-         * @param key Key.
-         */
-        void locked(Object key) {
-            locked.add(key);
-        }
-
-        /**
-         * Marks key as unlocked.
-         *
-         * @param key Key.
-         * @return {@code True} if last locked key was unlocked.
-         */
-        boolean unlocked(Object key) {
-            locked.remove(key);
-
-            return locked.isEmpty();
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegion.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegion.java
deleted file mode 100644
index 11a96d0..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegion.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import java.util.Collections;
-import java.util.Map;
-import org.apache.ignite.Ignite;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.Region;
-
-/**
- * Implementation of {@link Region}. This interface defines base contract for all L2 cache regions.
- */
-public class HibernateRegion implements Region {
-    /** */
-    protected final HibernateRegionFactory factory;
-
-    /** */
-    private final String name;
-
-    /** Cache instance. */
-    protected final HibernateCacheProxy cache;
-
-    /** Grid instance. */
-    protected Ignite ignite;
-
-    /**
-     * @param factory Region factory.
-     * @param name Region name.
-     * @param ignite Grid.
-     * @param cache Region cache.
-     */
-    public HibernateRegion(HibernateRegionFactory factory, String name, Ignite ignite, HibernateCacheProxy cache) {
-        this.factory = factory;
-        this.name = name;
-        this.ignite = ignite;
-        this.cache = cache;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String getName() {
-        return name;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void destroy() throws CacheException {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean contains(Object key) {
-        return cache.containsKey(key);
-    }
-
-    /** {@inheritDoc} */
-    @Override public long getSizeInMemory() {
-        return -1;
-    }
-
-    /** {@inheritDoc} */
-    @Override public long getElementCountInMemory() {
-        return cache.size();
-    }
-
-    /** {@inheritDoc} */
-    @Override public long getElementCountOnDisk() {
-        return -1;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Map toMap() {
-        return Collections.emptyMap();
-    }
-
-    /** {@inheritDoc} */
-    @Override public long nextTimestamp() {
-        return System.currentTimeMillis();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int getTimeout() {
-        return 0;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
deleted file mode 100644
index 263359b..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateRegionFactory.java
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
-import org.apache.ignite.internal.util.typedef.G;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.CacheDataDescription;
-import org.hibernate.cache.spi.CacheKey;
-import org.hibernate.cache.spi.CollectionRegion;
-import org.hibernate.cache.spi.EntityRegion;
-import org.hibernate.cache.spi.NaturalIdRegion;
-import org.hibernate.cache.spi.QueryResultsRegion;
-import org.hibernate.cache.spi.RegionFactory;
-import org.hibernate.cache.spi.TimestampsRegion;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cfg.Settings;
-
-import static org.hibernate.cache.spi.access.AccessType.NONSTRICT_READ_WRITE;
-
-/**
- * Hibernate L2 cache region factory.
- * <p>
- * Following Hibernate settings should be specified to enable second level cache and to use this
- * region factory for caching:
- * <pre name="code" class="brush: xml; gutter: false;">
- * hibernate.cache.use_second_level_cache=true
- * hibernate.cache.region.factory_class=org.apache.ignite.cache.hibernate.HibernateRegionFactory
- * </pre>
- * Note that before region factory is started you need to start properly configured Ignite node in the same JVM.
- * For example to start Ignite node one of loader provided in {@code org.apache.ignite.grid.startup} package can be used.
- * <p>
- * Name of Ignite instance to be used for region factory must be specified as following Hibernate property:
- * <pre name="code" class="brush: xml; gutter: false;">
- * org.apache.ignite.hibernate.ignite_instance_name=&lt;Ignite instance name&gt;
- * </pre>
- * Each Hibernate cache region must be associated with some {@link IgniteInternalCache}, by default it is assumed that
- * for each cache region there is a {@link IgniteInternalCache} with the same name. Also it is possible to define
- * region to cache mapping using properties with prefix {@code org.apache.ignite.hibernate.region_cache}.
- * For example if for region with name "region1" cache with name "cache1" should be used then following
- * Hibernate property should be specified:
- * <pre name="code" class="brush: xml; gutter: false;">
- * org.apache.ignite.hibernate.region_cache.region1=cache1
- * </pre>
- */
-public class HibernateRegionFactory implements RegionFactory {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /**
-     * Hibernate L2 cache grid name property name.
-     *
-     * @deprecated Use {@link #IGNITE_INSTANCE_NAME_PROPERTY}.
-     *      If {@link #IGNITE_INSTANCE_NAME_PROPERTY} is specified it takes precedence.
-     */
-    @Deprecated
-    public static final String GRID_NAME_PROPERTY = "org.apache.ignite.hibernate.grid_name";
-
-    /** Hibernate L2 cache Ignite instance name property name. */
-    public static final String IGNITE_INSTANCE_NAME_PROPERTY = "org.apache.ignite.hibernate.ignite_instance_name";
-
-    /** Default cache property name. */
-    public static final String DFLT_CACHE_NAME_PROPERTY = "org.apache.ignite.hibernate.default_cache";
-
-    /** Property prefix used to specify region name to cache name mapping. */
-    public static final String REGION_CACHE_PROPERTY = "org.apache.ignite.hibernate.region_cache.";
-
-    /** */
-    public static final String DFLT_ACCESS_TYPE_PROPERTY = "org.apache.ignite.hibernate.default_access_type";
-
-    /** */
-    public static final String GRID_CONFIG_PROPERTY = "org.apache.ignite.hibernate.grid_config";
-
-    /** Grid providing caches. */
-    private Ignite ignite;
-
-    /** Default cache. */
-    private HibernateCacheProxy dfltCache;
-
-    /** Default region access type. */
-    private AccessType dfltAccessType;
-
-    /** Region name to cache name mapping. */
-    private final Map<String, String> regionCaches = new HashMap<>();
-
-    /** Map needed to provide the same transaction context for different regions. */
-    private final ThreadLocal threadLoc = new ThreadLocal();
-
-    /** Key transformer. */
-    private final HibernateKeyTransformer hibernate4transformer = new HibernateKeyTransformer() {
-        @Override public Object transform(Object key) {
-            if (key instanceof CacheKey) {
-                CacheKey cacheKey = (CacheKey)key;
-
-                return new HibernateKeyWrapper(
-                    cacheKey.getKey(),
-                    cacheKey.getEntityOrRoleName(),
-                    cacheKey.getTenantId()
-                );
-            }
-
-            return key;
-        }
-    };
-
-    /** {@inheritDoc} */
-    @Override public void start(Settings settings, Properties props) throws CacheException {
-        String gridCfg = props.getProperty(GRID_CONFIG_PROPERTY);
-        String igniteInstanceName = props.getProperty(IGNITE_INSTANCE_NAME_PROPERTY);
-
-        if (igniteInstanceName == null)
-            igniteInstanceName = props.getProperty(GRID_NAME_PROPERTY);
-
-        if (gridCfg != null) {
-            try {
-                ignite = G.start(gridCfg);
-            }
-            catch (IgniteException e) {
-                throw new CacheException(e);
-            }
-        }
-        else
-            ignite = Ignition.ignite(igniteInstanceName);
-
-        String accessType = props.getProperty(DFLT_ACCESS_TYPE_PROPERTY, NONSTRICT_READ_WRITE.name());
-
-        dfltAccessType = AccessType.valueOf(accessType);
-
-        for (Map.Entry<Object, Object> prop : props.entrySet()) {
-            String key = prop.getKey().toString();
-
-            if (key.startsWith(REGION_CACHE_PROPERTY)) {
-                String regionName = key.substring(REGION_CACHE_PROPERTY.length());
-
-                String cacheName = prop.getValue().toString();
-
-                if (((IgniteKernal)ignite).getCache(cacheName) == null)
-                    throw new CacheException("Cache '" + cacheName + "' specified for region '" + regionName + "' " +
-                        "is not configured.");
-
-                regionCaches.put(regionName, cacheName);
-            }
-        }
-
-        String dfltCacheName = props.getProperty(DFLT_CACHE_NAME_PROPERTY);
-
-        if (dfltCacheName != null) {
-            IgniteInternalCache<Object, Object> dfltCache = ((IgniteKernal)ignite).getCache(dfltCacheName);
-
-            if (dfltCache == null)
-                throw new CacheException("Cache specified as default is not configured: " + dfltCacheName);
-
-            this.dfltCache = new HibernateCacheProxy(dfltCache, hibernate4transformer);
-        }
-
-        IgniteLogger log = ignite.log().getLogger(HibernateRegionFactory.class);
-
-        if (log.isDebugEnabled())
-            log.debug("HibernateRegionFactory started [igniteInstanceName=" + igniteInstanceName + ']');
-    }
-
-    /** {@inheritDoc} */
-    @Override public void stop() {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isMinimalPutsEnabledByDefault() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public AccessType getDefaultAccessType() {
-        return dfltAccessType;
-    }
-
-    /** {@inheritDoc} */
-    @Override public long nextTimestamp() {
-        return System.currentTimeMillis();
-    }
-
-    /** {@inheritDoc} */
-    @Override public EntityRegion buildEntityRegion(String regionName, Properties props, CacheDataDescription metadata)
-        throws CacheException {
-        return new HibernateEntityRegion(this, regionName, ignite, regionCache(regionName), metadata);
-    }
-
-    /** {@inheritDoc} */
-    @Override public NaturalIdRegion buildNaturalIdRegion(String regionName, Properties props,
-        CacheDataDescription metadata) throws CacheException {
-        return new HibernateNaturalIdRegion(this, regionName, ignite, regionCache(regionName), metadata);
-    }
-
-    /** {@inheritDoc} */
-    @Override public CollectionRegion buildCollectionRegion(String regionName, Properties props,
-        CacheDataDescription metadata) throws CacheException {
-        return new HibernateCollectionRegion(this, regionName, ignite, regionCache(regionName), metadata);
-    }
-
-    /** {@inheritDoc} */
-    @Override public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties props)
-        throws CacheException {
-        return new HibernateQueryResultsRegion(this, regionName, ignite, regionCache(regionName));
-    }
-
-    /** {@inheritDoc} */
-    @Override public TimestampsRegion buildTimestampsRegion(String regionName, Properties props) throws CacheException {
-        return new HibernateTimestampsRegion(this, regionName, ignite, regionCache(regionName));
-    }
-
-    /**
-     * Reuse same thread local for the same cache across different regions.
-     *
-     * @param cacheName Cache name.
-     * @return Thread local instance used to track updates done during one Hibernate transaction.
-     */
-    ThreadLocal threadLocalForCache(String cacheName) {
-        return threadLoc;
-    }
-
-    /**
-     * @param regionName L2 cache region name.
-     * @return Cache for given region.
-     * @throws CacheException If cache for given region is not configured.
-     */
-    private HibernateCacheProxy regionCache(String regionName) throws CacheException {
-        String cacheName = regionCaches.get(regionName);
-
-        if (cacheName == null) {
-            if (dfltCache != null)
-                return dfltCache;
-
-            cacheName = regionName;
-        }
-
-        IgniteInternalCache<Object, Object> cache = ((IgniteKernal)ignite).getCache(cacheName);
-
-        if (cache == null)
-            throw new CacheException("Cache '" + cacheName + "' for region '" + regionName + "' is not configured.");
-
-        return new HibernateCacheProxy(cache, hibernate4transformer);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateTimestampsRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateTimestampsRegion.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateTimestampsRegion.java
deleted file mode 100644
index 8b4c243..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateTimestampsRegion.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.apache.ignite.Ignite;
-import org.hibernate.cache.spi.TimestampsRegion;
-
-/**
- * Implementation of {@link TimestampsRegion}. This region is automatically created when query
- * caching is enabled and it holds most recent updates timestamps to queryable tables.
- * Name of timestamps region is {@code "org.hibernate.cache.spi.UpdateTimestampsCache"}.
- */
-public class HibernateTimestampsRegion extends HibernateGeneralDataRegion implements TimestampsRegion {
-    /**
-     * @param factory Region factory.
-     * @param name Region name.
-     * @param ignite Grid.
-     * @param cache Region cache.
-     */
-    public HibernateTimestampsRegion(HibernateRegionFactory factory, String name,
-        Ignite ignite,  HibernateCacheProxy cache) {
-        super(factory, name, ignite, cache);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalAccessStrategy.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalAccessStrategy.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalAccessStrategy.java
deleted file mode 100644
index ca52849..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalAccessStrategy.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.access.AccessType;
-import org.hibernate.cache.spi.access.SoftLock;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Implementation of {@link AccessType#TRANSACTIONAL} cache access strategy.
- * <p>
- * It is supposed that this strategy is used in JTA environment and Hibernate and
- * {@link IgniteInternalCache} corresponding to the L2 cache region are configured to use the same transaction manager.
- * <p>
- * Configuration of L2 cache and per-entity cache access strategy can be set in the
- * Hibernate configuration file:
- * <pre name="code" class="xml">
- * &lt;hibernate-configuration&gt;
- *     &lt;!-- Enable L2 cache. --&gt;
- *     &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
- *
- *     &lt;!-- Use Ignite as L2 cache provider. --&gt;
- *     &lt;property name="cache.region.factory_class"&gt;org.apache.ignite.cache.hibernate.HibernateRegionFactory&lt;/property&gt;
- *
- *     &lt;!-- Specify entity. --&gt;
- *     &lt;mapping class="com.example.Entity"/&gt;
- *
- *     &lt;!-- Enable L2 cache with transactional access strategy for entity. --&gt;
- *     &lt;class-cache class="com.example.Entity" usage="transactional"/&gt;
- * &lt;/hibernate-configuration&gt;
- * </pre>
- * Also cache access strategy can be set using annotations:
- * <pre name="code" class="java">
- * &#064;javax.persistence.Entity
- * &#064;javax.persistence.Cacheable
- * &#064;org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
- * public class Entity { ... }
- * </pre>
- */
-public class HibernateTransactionalAccessStrategy extends HibernateAccessStrategyAdapter {
-    /**
-     * @param ignite Grid.
-     * @param cache Cache.
-     */
-    public HibernateTransactionalAccessStrategy(Ignite ignite, HibernateCacheProxy cache) {
-        super(ignite, cache);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override protected Object get(Object key) throws CacheException {
-        try {
-            return cache.get(key);
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void putFromLoad(Object key, Object val) throws CacheException {
-        try {
-            cache.put(key, val);
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected SoftLock lock(Object key) throws CacheException {
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void unlock(Object key, SoftLock lock) throws CacheException {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean update(Object key, Object val) throws CacheException {
-        try {
-            cache.put(key, val);
-
-            return true;
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean afterUpdate(Object key, Object val, SoftLock lock) throws CacheException {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean insert(Object key, Object val) throws CacheException {
-        try {
-            cache.put(key, val);
-
-            return true;
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean afterInsert(Object key, Object val) throws CacheException {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void remove(Object key) throws CacheException {
-        try {
-            cache.remove(key);
-        }
-        catch (IgniteCheckedException e) {
-            throw new CacheException(e);
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java
deleted file mode 100644
index 581076a..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/HibernateTransactionalDataRegion.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.cache.hibernate;
-
-import org.apache.ignite.Ignite;
-import org.apache.ignite.configuration.TransactionConfiguration;
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.spi.CacheDataDescription;
-import org.hibernate.cache.spi.CollectionRegion;
-import org.hibernate.cache.spi.EntityRegion;
-import org.hibernate.cache.spi.NaturalIdRegion;
-import org.hibernate.cache.spi.TransactionalDataRegion;
-import org.hibernate.cache.spi.access.AccessType;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
-
-/**
- * Implementation of {@link TransactionalDataRegion} (transactional means that
- * data in the region is updated in connection with database transaction).
- * This interface defines base contract for {@link EntityRegion}, {@link CollectionRegion}
- * and {@link NaturalIdRegion}.
- */
-public class HibernateTransactionalDataRegion extends HibernateRegion implements TransactionalDataRegion {
-    /** */
-    private final CacheDataDescription dataDesc;
-
-    /**
-     * @param factory Region factory.
-     * @param name Region name.
-     * @param ignite Grid.
-     * @param cache Region cache.
-     * @param dataDesc Region data description.
-     */
-    public HibernateTransactionalDataRegion(HibernateRegionFactory factory, String name,
-        Ignite ignite, HibernateCacheProxy cache, CacheDataDescription dataDesc) {
-        super(factory, name, ignite, cache);
-
-        this.dataDesc = dataDesc;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isTransactionAware() {
-        return false; // This method is not used by Hibernate.
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheDataDescription getCacheDataDescription() {
-        return dataDesc;
-    }
-
-    /**
-     * @param accessType Hibernate L2 cache access type.
-     * @return Access strategy for given access type.
-     */
-    protected HibernateAccessStrategyAdapter createAccessStrategy(AccessType accessType) {
-        switch (accessType) {
-            case READ_ONLY:
-                return new HibernateReadOnlyAccessStrategy(ignite, cache);
-
-            case NONSTRICT_READ_WRITE:
-                return new HibernateNonStrictAccessStrategy(ignite, cache, factory.threadLocalForCache(cache.name()));
-
-            case READ_WRITE:
-                if (cache.configuration().getAtomicityMode() != TRANSACTIONAL)
-                    throw new CacheException("Hibernate READ-WRITE access strategy must have Ignite cache with " +
-                        "'TRANSACTIONAL' atomicity mode: " + cache.name());
-
-                return new HibernateReadWriteAccessStrategy(ignite, cache, factory.threadLocalForCache(cache.name()));
-
-            case TRANSACTIONAL:
-                if (cache.configuration().getAtomicityMode() != TRANSACTIONAL)
-                    throw new CacheException("Hibernate TRANSACTIONAL access strategy must have Ignite cache with " +
-                        "'TRANSACTIONAL' atomicity mode: " + cache.name());
-
-                TransactionConfiguration txCfg = ignite.configuration().getTransactionConfiguration();
-
-                if (txCfg == null ||
-                    (txCfg.getTxManagerFactory() == null
-                    && txCfg.getTxManagerLookupClassName() == null
-                    && cache.configuration().getTransactionManagerLookupClassName() == null)) {
-                    throw new CacheException("Hibernate TRANSACTIONAL access strategy must have Ignite with " +
-                                "Factory<TransactionManager> configured (see IgniteConfiguration." +
-                                "getTransactionConfiguration().setTxManagerFactory()): " + cache.name());
-                }
-
-                return new HibernateTransactionalAccessStrategy(ignite, cache);
-
-            default:
-                throw new IllegalArgumentException("Unknown Hibernate access type: " + accessType);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/package-info.java
----------------------------------------------------------------------
diff --git a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/package-info.java b/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/package-info.java
deleted file mode 100644
index 1179aec..0000000
--- a/modules/hibernate/src/main/java/org/apache/ignite/cache/hibernate/package-info.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * <!-- Package description. -->
- * Contains implementation of Hibernate L2 cache. Refer to
- * <i>org.apache.ignite.examples.datagrid.hibernate.HibernateL2CacheExample</i> for more information on how to
- * configure and use Ignite with Hibernate.
- */
-package org.apache.ignite.cache.hibernate;
\ No newline at end of file


[11/16] ignite git commit: ignite-1794 Refactored hibernate modules, switched to hibernate 5.1

Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java
new file mode 100644
index 0000000..f227af1
--- /dev/null
+++ b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheSelfTest.java
@@ -0,0 +1,1960 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.hibernate.ObjectNotFoundException;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.StaleStateException;
+import org.hibernate.Transaction;
+import org.hibernate.annotations.NaturalId;
+import org.hibernate.annotations.NaturalIdCache;
+import org.hibernate.boot.Metadata;
+import org.hibernate.boot.MetadataSources;
+import org.hibernate.boot.registry.StandardServiceRegistry;
+import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
+import org.hibernate.cache.spi.GeneralDataRegion;
+import org.hibernate.cache.spi.TransactionalDataRegion;
+import org.hibernate.cache.spi.access.AccessType;
+import org.hibernate.cfg.Environment;
+import org.hibernate.exception.ConstraintViolationException;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.RootClass;
+import org.hibernate.stat.NaturalIdCacheStatistics;
+import org.hibernate.stat.SecondLevelCacheStatistics;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.DFLT_ACCESS_TYPE_PROPERTY;
+import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.IGNITE_INSTANCE_NAME_PROPERTY;
+import static org.apache.ignite.cache.hibernate.HibernateAccessStrategyFactory.REGION_CACHE_PROPERTY;
+import static org.hibernate.cache.spi.access.AccessType.NONSTRICT_READ_WRITE;
+import static org.hibernate.cfg.Environment.CACHE_REGION_FACTORY;
+import static org.hibernate.cfg.Environment.GENERATE_STATISTICS;
+import static org.hibernate.cfg.Environment.HBM2DDL_AUTO;
+import static org.hibernate.cfg.Environment.RELEASE_CONNECTIONS;
+import static org.hibernate.cfg.Environment.USE_QUERY_CACHE;
+import static org.hibernate.cfg.Environment.USE_SECOND_LEVEL_CACHE;
+
+/**
+ *
+ * Tests Hibernate L2 cache.
+ */
+public class HibernateL2CacheSelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    public static final String CONNECTION_URL = "jdbc:h2:mem:example;DB_CLOSE_DELAY=-1";
+
+    /** */
+    public static final String ENTITY_NAME = Entity.class.getName();
+
+    /** */
+    public static final String ENTITY2_NAME = Entity2.class.getName();
+
+    /** */
+    public static final String VERSIONED_ENTITY_NAME = VersionedEntity.class.getName();
+
+    /** */
+    public static final String CHILD_ENTITY_NAME = ChildEntity.class.getName();
+
+    /** */
+    public static final String PARENT_ENTITY_NAME = ParentEntity.class.getName();
+
+    /** */
+    public static final String CHILD_COLLECTION_REGION = ENTITY_NAME + ".children";
+
+    /** */
+    public static final String NATURAL_ID_REGION =
+        "org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest$Entity##NaturalId";
+
+    /** */
+    public static final String NATURAL_ID_REGION2 =
+        "org.apache.ignite.cache.hibernate.HibernateL2CacheSelfTest$Entity2##NaturalId";
+
+    /** */
+    private SessionFactory sesFactory1;
+
+    /** */
+    private SessionFactory sesFactory2;
+
+    /**
+     * First Hibernate test entity.
+     */
+    @javax.persistence.Entity
+    @NaturalIdCache
+    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
+    public static class Entity {
+        /** */
+        private int id;
+
+        /** */
+        private String name;
+
+        /** */
+        private Collection<ChildEntity> children;
+
+        /**
+         * Default constructor required by Hibernate.
+         */
+        public Entity() {
+            // No-op.
+        }
+
+        /**
+         * @param id ID.
+         * @param name Name.
+         */
+        public Entity(int id, String name) {
+            this.id = id;
+            this.name = name;
+        }
+
+        /**
+         * @return ID.
+         */
+        @Id
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(int id) {
+            this.id = id;
+        }
+
+        /**
+         * @return Name.
+         */
+        @NaturalId(mutable = true)
+        public String getName() {
+            return name;
+        }
+
+        /**
+         * @param name Name.
+         */
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        /**
+         * @return Children.
+         */
+        @OneToMany(cascade=javax.persistence.CascadeType.ALL, fetch=FetchType.LAZY)
+        @JoinColumn(name="ENTITY_ID")
+        public Collection<ChildEntity> getChildren() {
+            return children;
+        }
+
+        /**
+         * @param children Children.
+         */
+        public void setChildren(Collection<ChildEntity> children) {
+            this.children = children;
+        }
+    }
+
+    /**
+     * Second Hibernate test entity.
+     */
+    @javax.persistence.Entity
+    @NaturalIdCache
+    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
+    public static class Entity2 {
+        /** */
+        private int id;
+
+        /** */
+        private String name;
+
+        /** */
+        private Collection<ChildEntity> children;
+
+        /**
+         * Default constructor required by Hibernate.
+         */
+        public Entity2() {
+            // No-op.
+        }
+
+        /**
+         * @param id ID.
+         * @param name Name.
+         */
+        public Entity2(int id, String name) {
+            this.id = id;
+            this.name = name;
+        }
+
+        /**
+         * @return ID.
+         */
+        @Id
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(int id) {
+            this.id = id;
+        }
+
+        /**
+         * @return Name.
+         */
+        @NaturalId(mutable = true)
+        public String getName() {
+            return name;
+        }
+
+        /**
+         * @param name Name.
+         */
+        public void setName(String name) {
+            this.name = name;
+        }
+    }
+
+    /**
+     * Hibernate child entity referenced by {@link Entity}.
+     */
+    @javax.persistence.Entity
+    @SuppressWarnings("PublicInnerClass")
+    public static class ChildEntity {
+        /** */
+        private int id;
+
+        /**
+         * Default constructor required by Hibernate.
+         */
+        public ChildEntity() {
+            // No-op.
+        }
+
+        /**
+         * @param id ID.
+         */
+        public ChildEntity(int id) {
+            this.id = id;
+        }
+
+        /**
+         * @return ID.
+         */
+        @Id
+        @GeneratedValue
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(int id) {
+            this.id = id;
+        }
+    }
+
+    /**
+     * Hibernate entity referencing {@link Entity}.
+     */
+    @javax.persistence.Entity
+    @SuppressWarnings("PublicInnerClass")
+    public static class ParentEntity {
+        /** */
+        private int id;
+
+        /** */
+        private Entity entity;
+
+        /**
+         * Default constructor required by Hibernate.
+         */
+        public ParentEntity() {
+            // No-op.
+        }
+
+        /**
+         * @param id ID.
+         * @param entity Referenced entity.
+         */
+        public ParentEntity(int id, Entity entity) {
+            this.id = id;
+            this.entity = entity;
+        }
+
+        /**
+         * @return ID.
+         */
+        @Id
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(int id) {
+            this.id = id;
+        }
+
+        /**
+         * @return Referenced entity.
+         */
+        @OneToOne
+        public Entity getEntity() {
+            return entity;
+        }
+
+        /**
+         * @param entity Referenced entity.
+         */
+        public void setEntity(Entity entity) {
+            this.entity = entity;
+        }
+    }
+
+    /**
+     * Hibernate entity.
+     */
+    @javax.persistence.Entity
+    @SuppressWarnings({"PublicInnerClass", "UnnecessaryFullyQualifiedName"})
+    public static class VersionedEntity {
+        /** */
+        private int id;
+
+        /** */
+        private long ver;
+
+        /**
+         * Default constructor required by Hibernate.
+         */
+        public VersionedEntity() {
+        }
+
+        /**
+         * @param id ID.
+         */
+        public VersionedEntity(int id) {
+            this.id = id;
+        }
+
+        /**
+         * @return ID.
+         */
+        @Id
+        public int getId() {
+            return id;
+        }
+
+        /**
+         * @param id ID.
+         */
+        public void setId(int id) {
+            this.id = id;
+        }
+
+        /**
+         * @return Version.
+         */
+        @javax.persistence.Version
+        public long getVersion() {
+            return ver;
+        }
+
+        /**
+         * @param ver Version.
+         */
+        public void setVersion(long ver) {
+            this.ver = ver;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
+
+        discoSpi.setIpFinder(IP_FINDER);
+
+        cfg.setDiscoverySpi(discoSpi);
+
+        cfg.setCacheConfiguration(generalRegionConfiguration("org.hibernate.cache.spi.UpdateTimestampsCache"),
+            generalRegionConfiguration("org.hibernate.cache.internal.StandardQueryCache"),
+            transactionalRegionConfiguration(ENTITY_NAME),
+            transactionalRegionConfiguration(ENTITY2_NAME),
+            transactionalRegionConfiguration(VERSIONED_ENTITY_NAME),
+            transactionalRegionConfiguration(PARENT_ENTITY_NAME),
+            transactionalRegionConfiguration(CHILD_ENTITY_NAME),
+            transactionalRegionConfiguration(CHILD_COLLECTION_REGION),
+            transactionalRegionConfiguration(NATURAL_ID_REGION),
+            transactionalRegionConfiguration(NATURAL_ID_REGION2));
+
+        return cfg;
+    }
+
+    /**
+     * @param regionName Region name.
+     * @return Cache configuration for {@link GeneralDataRegion}.
+     */
+    private CacheConfiguration generalRegionConfiguration(String regionName) {
+        CacheConfiguration cfg = new CacheConfiguration();
+
+        cfg.setName(regionName);
+
+        cfg.setCacheMode(PARTITIONED);
+
+        cfg.setAtomicityMode(ATOMIC);
+
+        cfg.setWriteSynchronizationMode(FULL_SYNC);
+
+        cfg.setBackups(1);
+
+        cfg.setAffinity(new RendezvousAffinityFunction(false, 10));
+
+        return cfg;
+    }
+
+    /**
+     * @param regionName Region name.
+     * @return Cache configuration for {@link TransactionalDataRegion}.
+     */
+    protected CacheConfiguration transactionalRegionConfiguration(String regionName) {
+        CacheConfiguration cfg = new CacheConfiguration();
+
+        cfg.setName(regionName);
+
+        cfg.setCacheMode(PARTITIONED);
+
+        cfg.setAtomicityMode(TRANSACTIONAL);
+
+        cfg.setWriteSynchronizationMode(FULL_SYNC);
+
+        cfg.setBackups(1);
+
+        cfg.setAffinity(new RendezvousAffinityFunction(false, 10));
+
+        return cfg;
+    }
+
+    /**
+     * @return Hibernate registry builder.
+     */
+    protected StandardServiceRegistryBuilder registryBuilder() {
+        StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
+
+        builder.applySetting("hibernate.connection.url", CONNECTION_URL);
+
+        return builder;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrids(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        cleanup();
+    }
+
+    /**
+     * @return Hibernate L2 cache access types to test.
+     */
+    protected AccessType[] accessTypes() {
+        return new AccessType[]{AccessType.READ_ONLY, AccessType.NONSTRICT_READ_WRITE, AccessType.READ_WRITE};
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCollectionCache() throws Exception {
+        for (AccessType accessType : accessTypes())
+            testCollectionCache(accessType);
+    }
+
+    /**
+     * @param accessType Cache access type.
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings("unchecked")
+    private void testCollectionCache(AccessType accessType) throws Exception {
+        createSessionFactories(accessType);
+
+        Map<Integer, Integer> idToChildCnt = new HashMap<>();
+
+        try {
+            Session ses = sesFactory1.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                for (int i = 0; i < 3; i++) {
+                    Entity e = new Entity(i, "name-" + i);
+
+                    Collection<ChildEntity> children = new ArrayList<>();
+
+                    for (int j = 0; j < 3; j++)
+                        children.add(new ChildEntity());
+
+                    e.setChildren(children);
+
+                    idToChildCnt.put(e.getId(), e.getChildren().size());
+
+                    ses.save(e);
+                }
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            // Load children, this should populate cache.
+
+            ses = sesFactory1.openSession();
+
+            try {
+                List<Entity> list = ses.createCriteria(ENTITY_NAME).list();
+
+                assertEquals(idToChildCnt.size(), list.size());
+
+                for (Entity e : list)
+                    assertEquals((int)idToChildCnt.get(e.getId()), e.getChildren().size());
+            }
+            finally {
+                ses.close();
+            }
+
+            assertCollectionCache(sesFactory2, idToChildCnt, 3, 0);
+            assertCollectionCache(sesFactory1, idToChildCnt, 3, 0);
+
+            if (accessType == AccessType.READ_ONLY)
+                return;
+
+            // Update children for one entity.
+
+            ses = sesFactory1.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                Entity e1 = (Entity)ses.load(Entity.class, 1);
+
+                e1.getChildren().remove(e1.getChildren().iterator().next());
+
+                ses.update(e1);
+
+                idToChildCnt.put(e1.getId(), e1.getChildren().size());
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertCollectionCache(sesFactory2, idToChildCnt, 2, 1); // After update collection cache entry is removed.
+            assertCollectionCache(sesFactory1, idToChildCnt, 3, 0); // 'assertCollectionCache' loads children in cache.
+
+            // Update children for the same entity using another SessionFactory.
+
+            ses = sesFactory2.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                Entity e1 = (Entity)ses.load(Entity.class, 1);
+
+                e1.getChildren().remove(e1.getChildren().iterator().next());
+
+                ses.update(e1);
+
+                idToChildCnt.put(e1.getId(), e1.getChildren().size());
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertCollectionCache(sesFactory2, idToChildCnt, 2, 1); // After update collection cache entry is removed.
+            assertCollectionCache(sesFactory1, idToChildCnt, 3, 0); // 'assertCollectionCache' loads children in cache.
+        }
+        finally {
+            cleanup();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testEntityCache() throws Exception {
+        for (AccessType accessType : accessTypes())
+            testEntityCache(accessType);
+    }
+
+    /**
+     * @param accessType Cache access type.
+     * @throws Exception If failed.
+     */
+    private void testEntityCache(AccessType accessType) throws Exception {
+        createSessionFactories(accessType);
+
+        Map<Integer, String> idToName = new HashMap<>();
+
+        try {
+            Session ses = sesFactory1.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                for (int i = 0; i < 2; i++) {
+                    String name = "name-" + i;
+
+                    ses.save(new Entity(i, name));
+
+                    idToName.put(i, name);
+                }
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName, 100);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName, 100);
+
+            if (accessType == AccessType.READ_ONLY)
+                return;
+
+            ses = sesFactory1.openSession();
+
+            try {
+                // Updates and inserts in single transaction.
+
+                Transaction tx = ses.beginTransaction();
+
+                Entity e0 = (Entity)ses.load(Entity.class, 0);
+
+                e0.setName("name-0-changed1");
+
+                ses.update(e0);
+
+                idToName.put(0, e0.getName());
+
+                ses.save(new Entity(2, "name-2"));
+
+                idToName.put(2, "name-2");
+
+                Entity e1 = (Entity)ses.load(Entity.class, 1);
+
+                e1.setName("name-1-changed1");
+
+                ses.update(e1);
+
+                idToName.put(1, e1.getName());
+
+                ses.save(new Entity(3, "name-3"));
+
+                idToName.put(3, "name-3");
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName);
+
+            ses = sesFactory1.openSession();
+
+            try {
+                // Updates, inserts and deletes in single transaction.
+
+                Transaction tx = ses.beginTransaction();
+
+                ses.save(new Entity(4, "name-4"));
+
+                idToName.put(4, "name-4");
+
+                Entity e0 = (Entity)ses.load(Entity.class, 0);
+
+                e0.setName("name-0-changed2");
+
+                ses.update(e0);
+
+                idToName.put(e0.getId(), e0.getName());
+
+                ses.delete(ses.load(Entity.class, 1));
+
+                idToName.remove(1);
+
+                Entity e2 = (Entity)ses.load(Entity.class, 2);
+
+                e2.setName("name-2-changed1");
+
+                ses.update(e2);
+
+                idToName.put(e2.getId(), e2.getName());
+
+                ses.delete(ses.load(Entity.class, 3));
+
+                idToName.remove(3);
+
+                ses.save(new Entity(5, "name-5"));
+
+                idToName.put(5, "name-5");
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName, 1, 3);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName, 1, 3);
+
+            // Try to update the same entity using another SessionFactory.
+
+            ses = sesFactory2.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                Entity e0 = (Entity)ses.load(Entity.class, 0);
+
+                e0.setName("name-0-changed3");
+
+                ses.update(e0);
+
+                idToName.put(e0.getId(), e0.getName());
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName);
+        }
+        finally {
+            cleanup();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTwoEntitiesSameCache() throws Exception {
+        for (AccessType accessType : accessTypes())
+            testTwoEntitiesSameCache(accessType);
+    }
+
+    /**
+     * @param accessType Cache access type.
+     * @throws Exception If failed.
+     */
+    private void testTwoEntitiesSameCache(AccessType accessType) throws Exception {
+        createSessionFactories(accessType);
+
+        try {
+            Session ses = sesFactory1.openSession();
+
+            Map<Integer, String> idToName1 = new HashMap<>();
+            Map<Integer, String> idToName2 = new HashMap<>();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                for (int i = 0; i < 2; i++) {
+                    String name = "name-" + i;
+
+                    ses.save(new Entity(i, name));
+                    ses.save(new Entity2(i, name));
+
+                    idToName1.put(i, name);
+                    idToName2.put(i, name);
+                }
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName1, 100);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName1, 100);
+
+            assertEntityCache(ENTITY2_NAME, sesFactory2, idToName2, 100);
+            assertEntityCache(ENTITY2_NAME, sesFactory1, idToName2, 100);
+
+            if (accessType == AccessType.READ_ONLY)
+                return;
+
+            ses = sesFactory1.openSession();
+
+            try {
+                // Updates both entities in single transaction.
+
+                Transaction tx = ses.beginTransaction();
+
+                Entity e = (Entity)ses.load(Entity.class, 0);
+
+                e.setName("name-0-changed1");
+
+                ses.update(e);
+
+                Entity2 e2 = (Entity2)ses.load(Entity2.class, 0);
+
+                e2.setName("name-e2-0-changed1");
+
+                ses.update(e2);
+
+                idToName1.put(0, e.getName());
+                idToName2.put(0, e2.getName());
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName1, 100);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName1, 100);
+
+            assertEntityCache(ENTITY2_NAME, sesFactory2, idToName2, 100);
+            assertEntityCache(ENTITY2_NAME, sesFactory1, idToName2, 100);
+
+            ses = sesFactory1.openSession();
+
+            try {
+                // Remove entity1 and insert entity2 in single transaction.
+
+                Transaction tx = ses.beginTransaction();
+
+                Entity e = (Entity)ses.load(Entity.class, 0);
+
+                ses.delete(e);
+
+                Entity2 e2 = new Entity2(2, "name-2");
+
+                ses.save(e2);
+
+                idToName1.remove(0);
+                idToName2.put(2, e2.getName());
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName1, 0, 100);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName1, 0, 100);
+
+            assertEntityCache(ENTITY2_NAME, sesFactory2, idToName2, 100);
+            assertEntityCache(ENTITY2_NAME, sesFactory1, idToName2, 100);
+
+            ses = sesFactory1.openSession();
+
+            Transaction tx = ses.beginTransaction();
+
+            try {
+                // Update, remove, insert in single transaction, transaction fails.
+
+                Entity e = (Entity)ses.load(Entity.class, 1);
+
+                e.setName("name-1-changed1");
+
+                ses.update(e); // Valid update.
+
+                ses.save(new Entity(2, "name-2")); // Valid insert.
+
+                ses.delete(ses.load(Entity2.class, 0)); // Valid delete.
+
+                Entity2 e2 = (Entity2)ses.load(Entity2.class, 1);
+
+                e2.setName("name-2");  // Invalid update, not-unique name.
+
+                ses.update(e2);
+
+                tx.commit();
+
+                fail("Commit must fail.");
+            }
+            catch (ConstraintViolationException e) {
+                log.info("Expected exception: " + e);
+
+                tx.rollback();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName1, 0, 2, 100);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName1, 0, 2, 100);
+
+            assertEntityCache(ENTITY2_NAME, sesFactory2, idToName2, 100);
+            assertEntityCache(ENTITY2_NAME, sesFactory1, idToName2, 100);
+
+            ses = sesFactory2.openSession();
+
+            try {
+                // Update, remove, insert in single transaction.
+
+                tx = ses.beginTransaction();
+
+                Entity e = (Entity)ses.load(Entity.class, 1);
+
+                e.setName("name-1-changed1");
+
+                ses.update(e);
+
+                idToName1.put(1, e.getName());
+
+                ses.save(new Entity(2, "name-2"));
+
+                idToName1.put(2, "name-2");
+
+                ses.delete(ses.load(Entity2.class, 0));
+
+                idToName2.remove(0);
+
+                Entity2 e2 = (Entity2)ses.load(Entity2.class, 1);
+
+                e2.setName("name-e2-2-changed");
+
+                ses.update(e2);
+
+                idToName2.put(1, e2.getName());
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName1, 0, 100);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName1, 0, 100);
+
+            assertEntityCache(ENTITY2_NAME, sesFactory2, idToName2, 0, 100);
+            assertEntityCache(ENTITY2_NAME, sesFactory1, idToName2, 0, 100);
+        }
+        finally {
+            cleanup();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testVersionedEntity() throws Exception {
+        for (AccessType accessType : accessTypes())
+            testVersionedEntity(accessType);
+    }
+
+    /**
+     * @param accessType Cache access type.
+     * @throws Exception If failed.
+     */
+    private void testVersionedEntity(AccessType accessType) throws Exception {
+        createSessionFactories(accessType);
+
+        try {
+            Session ses = sesFactory1.openSession();
+
+            VersionedEntity e0 = new VersionedEntity(0);
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                ses.save(e0);
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            ses = sesFactory1.openSession();
+
+            long ver;
+
+            try {
+                ver = ((VersionedEntity)ses.load(VersionedEntity.class, 0)).getVersion();
+            }
+            finally {
+                ses.close();
+            }
+
+            SecondLevelCacheStatistics stats1 =
+                sesFactory1.getStatistics().getSecondLevelCacheStatistics(VERSIONED_ENTITY_NAME);
+            SecondLevelCacheStatistics stats2 =
+                sesFactory2.getStatistics().getSecondLevelCacheStatistics(VERSIONED_ENTITY_NAME);
+
+            assertEquals(1, stats1.getElementCountInMemory());
+            assertEquals(1, stats2.getElementCountInMemory());
+
+            ses = sesFactory2.openSession();
+
+            try {
+                assertEquals(ver, ((VersionedEntity)ses.load(VersionedEntity.class, 0)).getVersion());
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEquals(1, stats2.getElementCountInMemory());
+            assertEquals(1, stats2.getHitCount());
+
+            if (accessType == AccessType.READ_ONLY)
+                return;
+
+            e0.setVersion(ver - 1);
+
+            ses = sesFactory1.openSession();
+
+            Transaction tx = ses.beginTransaction();
+
+            try {
+                ses.update(e0);
+
+                tx.commit();
+
+                fail("Commit must fail.");
+            }
+            catch (StaleStateException e) {
+                log.info("Expected exception: " + e);
+            }
+            finally {
+                tx.rollback();
+
+                ses.close();
+            }
+
+            sesFactory1.getStatistics().clear();
+
+            stats1 = sesFactory1.getStatistics().getSecondLevelCacheStatistics(VERSIONED_ENTITY_NAME);
+
+            ses = sesFactory1.openSession();
+
+            try {
+                assertEquals(ver, ((VersionedEntity)ses.load(VersionedEntity.class, 0)).getVersion());
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEquals(1, stats1.getElementCountInMemory());
+            assertEquals(1, stats1.getHitCount());
+            assertEquals(1, stats2.getElementCountInMemory());
+            assertEquals(1, stats2.getHitCount());
+        }
+        finally {
+            cleanup();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNaturalIdCache() throws Exception {
+        for (AccessType accessType : accessTypes())
+            testNaturalIdCache(accessType);
+    }
+
+    /**
+     * @param accessType Cache access type.
+     * @throws Exception If failed.
+     */
+    private void testNaturalIdCache(AccessType accessType) throws Exception {
+        createSessionFactories(accessType);
+
+        Map<String, Integer> nameToId = new HashMap<>();
+
+        try {
+            Session ses = sesFactory1.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                for (int i = 0; i < 3; i++) {
+                    String name = "name-" + i;
+
+                    ses.save(new Entity(i, name));
+
+                    nameToId.put(name, i);
+                }
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            ses = sesFactory1.openSession();
+
+            try {
+                for (Map.Entry<String, Integer> e : nameToId.entrySet())
+                    ((Entity)ses.bySimpleNaturalId(Entity.class).load(e.getKey())).getId();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertNaturalIdCache(sesFactory2, nameToId, "name-100");
+            assertNaturalIdCache(sesFactory1, nameToId, "name-100");
+
+            if (accessType == AccessType.READ_ONLY)
+                return;
+
+            // Update naturalId.
+
+            ses = sesFactory1.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                Entity e1 = (Entity)ses.load(Entity.class, 1);
+
+                nameToId.remove(e1.getName());
+
+                e1.setName("name-1-changed1");
+
+                nameToId.put(e1.getName(), e1.getId());
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertNaturalIdCache(sesFactory2, nameToId, "name-1");
+            assertNaturalIdCache(sesFactory1, nameToId, "name-1");
+
+            // Update entity using another SessionFactory.
+
+            ses = sesFactory2.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                Entity e1 = (Entity)ses.load(Entity.class, 1);
+
+                nameToId.remove(e1.getName());
+
+                e1.setName("name-1-changed2");
+
+                nameToId.put(e1.getName(), e1.getId());
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertNaturalIdCache(sesFactory2, nameToId, "name-1-changed1");
+            assertNaturalIdCache(sesFactory1, nameToId, "name-1-changed1");
+
+            // Try invalid NaturalId update.
+
+            ses = sesFactory1.openSession();
+
+            Transaction tx = ses.beginTransaction();
+
+            try {
+                Entity e1 = (Entity)ses.load(Entity.class, 1);
+
+                e1.setName("name-0"); // Invalid update (duplicated name).
+
+                tx.commit();
+
+                fail("Commit must fail.");
+            }
+            catch (ConstraintViolationException e) {
+                log.info("Expected exception: " + e);
+
+                tx.rollback();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertNaturalIdCache(sesFactory2, nameToId);
+            assertNaturalIdCache(sesFactory1, nameToId);
+
+            // Delete entity.
+
+            ses = sesFactory2.openSession();
+
+            try {
+                tx = ses.beginTransaction();
+
+                Entity e2 = (Entity)ses.load(Entity.class, 2);
+
+                ses.delete(e2);
+
+                nameToId.remove(e2.getName());
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertNaturalIdCache(sesFactory2, nameToId, "name-2");
+            assertNaturalIdCache(sesFactory1, nameToId, "name-2");
+        }
+        finally {
+            cleanup();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testEntityCacheTransactionFails() throws Exception {
+        for (AccessType accessType : accessTypes())
+            testEntityCacheTransactionFails(accessType);
+    }
+
+    /**
+     * @param accessType Cache access type.
+     * @throws Exception If failed.
+     */
+    private void testEntityCacheTransactionFails(AccessType accessType) throws Exception {
+        createSessionFactories(accessType);
+
+        Map<Integer, String> idToName = new HashMap<>();
+
+        try {
+            Session ses = sesFactory1.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                for (int i = 0; i < 3; i++) {
+                    String name = "name-" + i;
+
+                    ses.save(new Entity(i, name));
+
+                    idToName.put(i, name);
+                }
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName, 100);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName, 100);
+
+            ses = sesFactory1.openSession();
+
+            Transaction tx = ses.beginTransaction();
+
+            try {
+                ses.save(new Entity(3, "name-3")); // Valid insert.
+
+                ses.save(new Entity(0, "name-0")); // Invalid insert (duplicated ID).
+
+                tx.commit();
+
+                fail("Commit must fail.");
+            }
+            catch (ConstraintViolationException e) {
+                log.info("Expected exception: " + e);
+
+                tx.rollback();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName, 3);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName, 3);
+
+            if (accessType == AccessType.READ_ONLY)
+                return;
+
+            ses = sesFactory1.openSession();
+
+            tx = ses.beginTransaction();
+
+            try {
+                Entity e0 = (Entity)ses.load(Entity.class, 0);
+                Entity e1 = (Entity)ses.load(Entity.class, 1);
+
+                e0.setName("name-10"); // Valid update.
+                e1.setName("name-2"); // Invalid update (violates unique constraint).
+
+                ses.update(e0);
+                ses.update(e1);
+
+                tx.commit();
+
+                fail("Commit must fail.");
+            }
+            catch (ConstraintViolationException e) {
+                log.info("Expected exception: " + e);
+
+                tx.rollback();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName);
+
+            ses = sesFactory1.openSession();
+
+            try {
+                // Create parent entity referencing Entity with ID = 0.
+
+                tx = ses.beginTransaction();
+
+                ses.save(new ParentEntity(0, (Entity) ses.load(Entity.class, 0)));
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            ses = sesFactory1.openSession();
+
+            tx = ses.beginTransaction();
+
+            try {
+                ses.save(new Entity(3, "name-3")); // Valid insert.
+
+                Entity e1 = (Entity)ses.load(Entity.class, 1);
+
+                e1.setName("name-10"); // Valid update.
+
+                ses.delete(ses.load(Entity.class, 0)); // Invalid delete (there is a parent entity referencing it).
+
+                tx.commit();
+
+                fail("Commit must fail.");
+            }
+            catch (ConstraintViolationException e) {
+                log.info("Expected exception: " + e);
+
+                tx.rollback();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName, 3);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName, 3);
+
+            ses = sesFactory1.openSession();
+
+            tx = ses.beginTransaction();
+
+            try {
+                ses.delete(ses.load(Entity.class, 1)); // Valid delete.
+
+                idToName.remove(1);
+
+                ses.delete(ses.load(Entity.class, 0)); // Invalid delete (there is a parent entity referencing it).
+
+                tx.commit();
+
+                fail("Commit must fail.");
+            }
+            catch (ConstraintViolationException e) {
+                log.info("Expected exception: " + e);
+
+                tx.rollback();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEntityCache(ENTITY_NAME, sesFactory2, idToName);
+            assertEntityCache(ENTITY_NAME, sesFactory1, idToName);
+        }
+        finally {
+            cleanup();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testQueryCache() throws Exception {
+        for (AccessType accessType : accessTypes())
+            testQueryCache(accessType);
+    }
+
+    /**
+     * @param accessType Cache access type.
+     * @throws Exception If failed.
+     */
+    private void testQueryCache(AccessType accessType) throws Exception {
+        createSessionFactories(accessType);
+
+        try {
+            Session ses = sesFactory1.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                for (int i = 0; i < 5; i++)
+                    ses.save(new Entity(i, "name-" + i));
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            // Run some queries.
+
+            ses = sesFactory1.openSession();
+
+            try {
+                Query qry1 = ses.createQuery("from " + ENTITY_NAME + " where id > 2");
+
+                qry1.setCacheable(true);
+
+                assertEquals(2, qry1.list().size());
+
+                Query qry2 = ses.createQuery("from " + ENTITY_NAME + " where name = 'name-0'");
+
+                qry2.setCacheable(true);
+
+                assertEquals(1, qry2.list().size());
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEquals(0, sesFactory1.getStatistics().getQueryCacheHitCount());
+            assertEquals(2, sesFactory1.getStatistics().getQueryCacheMissCount());
+            assertEquals(2, sesFactory1.getStatistics().getQueryCachePutCount());
+
+            // Run queries using another SessionFactory.
+
+            ses = sesFactory2.openSession();
+
+            try {
+                Query qry1 = ses.createQuery("from " + ENTITY_NAME + " where id > 2");
+
+                qry1.setCacheable(true);
+
+                assertEquals(2, qry1.list().size());
+
+                Query qry2 = ses.createQuery("from " + ENTITY_NAME + " where name = 'name-0'");
+
+                qry2.setCacheable(true);
+
+                assertEquals(1, qry2.list().size());
+
+                Query qry3 = ses.createQuery("from " + ENTITY_NAME + " where id > 1");
+
+                qry3.setCacheable(true);
+
+                assertEquals(3, qry3.list().size());
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEquals(2, sesFactory2.getStatistics().getQueryCacheHitCount());
+            assertEquals(1, sesFactory2.getStatistics().getQueryCacheMissCount());
+            assertEquals(1, sesFactory2.getStatistics().getQueryCachePutCount());
+
+            // Update entity, it should invalidate query cache.
+
+            ses = sesFactory1.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                ses.save(new Entity(5, "name-5"));
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            // Run queries.
+
+            ses = sesFactory1.openSession();
+
+            sesFactory1.getStatistics().clear();
+
+            try {
+                Query qry1 = ses.createQuery("from " + ENTITY_NAME + " where id > 2");
+
+                qry1.setCacheable(true);
+
+                assertEquals(3, qry1.list().size());
+
+                Query qry2 = ses.createQuery("from " + ENTITY_NAME + " where name = 'name-0'");
+
+                qry2.setCacheable(true);
+
+                assertEquals(1, qry2.list().size());
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEquals(0, sesFactory1.getStatistics().getQueryCacheHitCount());
+            assertEquals(2, sesFactory1.getStatistics().getQueryCacheMissCount());
+            assertEquals(2, sesFactory1.getStatistics().getQueryCachePutCount());
+
+            // Clear query cache using another SessionFactory.
+
+            sesFactory2.getCache().evictDefaultQueryRegion();
+
+            ses = sesFactory1.openSession();
+
+            // Run queries again.
+
+            sesFactory1.getStatistics().clear();
+
+            try {
+                Query qry1 = ses.createQuery("from " + ENTITY_NAME + " where id > 2");
+
+                qry1.setCacheable(true);
+
+                assertEquals(3, qry1.list().size());
+
+                Query qry2 = ses.createQuery("from " + ENTITY_NAME + " where name = 'name-0'");
+
+                qry2.setCacheable(true);
+
+                assertEquals(1, qry2.list().size());
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEquals(0, sesFactory1.getStatistics().getQueryCacheHitCount());
+            assertEquals(2, sesFactory1.getStatistics().getQueryCacheMissCount());
+            assertEquals(2, sesFactory1.getStatistics().getQueryCachePutCount());
+        }
+        finally {
+            cleanup();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testRegionClear() throws Exception {
+        for (AccessType accessType : accessTypes())
+            testRegionClear(accessType);
+    }
+
+    /**
+     * @param accessType Cache access type.
+     * @throws Exception If failed.
+     */
+    private void testRegionClear(AccessType accessType) throws Exception {
+        createSessionFactories(accessType);
+
+        try {
+            final int ENTITY_CNT = 100;
+
+            Session ses = sesFactory1.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                for (int i = 0; i < ENTITY_CNT; i++) {
+                    Entity e = new Entity(i, "name-" + i);
+
+                    Collection<ChildEntity> children = new ArrayList<>();
+
+                    for (int j = 0; j < 3; j++)
+                        children.add(new ChildEntity());
+
+                    e.setChildren(children);
+
+                    ses.save(e);
+                }
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            loadEntities(sesFactory2, ENTITY_CNT);
+
+            SecondLevelCacheStatistics stats1 = sesFactory1.getStatistics().getSecondLevelCacheStatistics(ENTITY_NAME);
+            SecondLevelCacheStatistics stats2 = sesFactory2.getStatistics().getSecondLevelCacheStatistics(ENTITY_NAME);
+
+            NaturalIdCacheStatistics idStats1 =
+                sesFactory1.getStatistics().getNaturalIdCacheStatistics(NATURAL_ID_REGION);
+            NaturalIdCacheStatistics idStats2 =
+                sesFactory2.getStatistics().getNaturalIdCacheStatistics(NATURAL_ID_REGION);
+
+            SecondLevelCacheStatistics colStats1 =
+                sesFactory1.getStatistics().getSecondLevelCacheStatistics(CHILD_COLLECTION_REGION);
+            SecondLevelCacheStatistics colStats2 =
+                sesFactory2.getStatistics().getSecondLevelCacheStatistics(CHILD_COLLECTION_REGION);
+
+            assertEquals(ENTITY_CNT, stats1.getElementCountInMemory());
+            assertEquals(ENTITY_CNT, stats2.getElementCountInMemory());
+
+            assertEquals(ENTITY_CNT, idStats1.getElementCountInMemory());
+            assertEquals(ENTITY_CNT, idStats2.getElementCountInMemory());
+
+            assertEquals(ENTITY_CNT, colStats1.getElementCountInMemory());
+            assertEquals(ENTITY_CNT, colStats2.getElementCountInMemory());
+
+            // Test cache is cleared after update query.
+
+            ses = sesFactory1.openSession();
+
+            try {
+                Transaction tx = ses.beginTransaction();
+
+                ses.createQuery("delete from " + ENTITY_NAME + " where name='no such name'").executeUpdate();
+
+                ses.createQuery("delete from " + ChildEntity.class.getName() + " where id=-1").executeUpdate();
+
+                tx.commit();
+            }
+            finally {
+                ses.close();
+            }
+
+            assertEquals(0, stats1.getElementCountInMemory());
+            assertEquals(0, stats2.getElementCountInMemory());
+
+            assertEquals(0, idStats1.getElementCountInMemory());
+            assertEquals(0, idStats2.getElementCountInMemory());
+
+            assertEquals(0, colStats1.getElementCountInMemory());
+            assertEquals(0, colStats2.getElementCountInMemory());
+
+            // Load some data in cache.
+
+            loadEntities(sesFactory1, 10);
+
+            assertEquals(10, stats1.getElementCountInMemory());
+            assertEquals(10, stats2.getElementCountInMemory());
+            assertEquals(10, idStats1.getElementCountInMemory());
+            assertEquals(10, idStats2.getElementCountInMemory());
+
+            // Test evictAll method.
+
+            sesFactory2.getCache().evictEntityRegion(ENTITY_NAME);
+
+            assertEquals(0, stats1.getElementCountInMemory());
+            assertEquals(0, stats2.getElementCountInMemory());
+
+            sesFactory2.getCache().evictNaturalIdRegion(ENTITY_NAME);
+
+            assertEquals(0, idStats1.getElementCountInMemory());
+            assertEquals(0, idStats2.getElementCountInMemory());
+
+            sesFactory2.getCache().evictCollectionRegion(CHILD_COLLECTION_REGION);
+
+            assertEquals(0, colStats1.getElementCountInMemory());
+            assertEquals(0, colStats2.getElementCountInMemory());
+        }
+        finally {
+            cleanup();
+        }
+    }
+
+    /**
+     * @param sesFactory Session factory.
+     * @param nameToId Name-ID mapping.
+     * @param absentNames Absent entities' names.
+     */
+    private void assertNaturalIdCache(SessionFactory sesFactory, Map<String, Integer> nameToId, String... absentNames) {
+        sesFactory.getStatistics().clear();
+
+        NaturalIdCacheStatistics stats =
+            sesFactory.getStatistics().getNaturalIdCacheStatistics(NATURAL_ID_REGION);
+
+        long hitBefore = stats.getHitCount();
+
+        long missBefore = stats.getMissCount();
+
+        final Session ses = sesFactory.openSession();
+
+        try {
+            for (Map.Entry<String, Integer> e : nameToId.entrySet())
+                assertEquals((int)e.getValue(), ((Entity)ses.bySimpleNaturalId(Entity.class).load(e.getKey())).getId());
+
+            for (String name : absentNames)
+                assertNull((ses.bySimpleNaturalId(Entity.class).load(name)));
+
+            assertEquals(nameToId.size() + hitBefore, stats.getHitCount());
+
+            assertEquals(absentNames.length + missBefore, stats.getMissCount());
+        }
+        finally {
+            ses.close();
+        }
+    }
+
+    /**
+     * @param sesFactory Session factory.
+     * @param idToChildCnt Number of children per entity.
+     * @param expHit Expected cache hits.
+     * @param expMiss Expected cache misses.
+     */
+    @SuppressWarnings("unchecked")
+    private void assertCollectionCache(SessionFactory sesFactory, Map<Integer, Integer> idToChildCnt, int expHit,
+        int expMiss) {
+        sesFactory.getStatistics().clear();
+
+        Session ses = sesFactory.openSession();
+
+        try {
+            for(Map.Entry<Integer, Integer> e : idToChildCnt.entrySet()) {
+                Entity entity = (Entity)ses.load(Entity.class, e.getKey());
+
+                assertEquals((int)e.getValue(), entity.getChildren().size());
+            }
+        }
+        finally {
+            ses.close();
+        }
+
+        SecondLevelCacheStatistics stats =
+            sesFactory.getStatistics().getSecondLevelCacheStatistics(CHILD_COLLECTION_REGION);
+
+        assertEquals(expHit, stats.getHitCount());
+
+        assertEquals(expMiss, stats.getMissCount());
+    }
+
+    /**
+     * @param sesFactory Session factory.
+     * @param cnt Number of entities to load.
+     */
+    private void loadEntities(SessionFactory sesFactory, int cnt) {
+        Session ses = sesFactory.openSession();
+
+        try {
+            for (int i = 0; i < cnt; i++) {
+                Entity e = (Entity)ses.load(Entity.class, i);
+
+                assertEquals("name-" + i, e.getName());
+
+                assertFalse(e.getChildren().isEmpty());
+
+                ses.bySimpleNaturalId(Entity.class).load(e.getName());
+            }
+        }
+        finally {
+            ses.close();
+        }
+    }
+
+    /**
+     * @param entityName Entity name.
+     * @param sesFactory Session factory.
+     * @param idToName ID to name mapping.
+     * @param absentIds Absent entities' IDs.
+     */
+    private void assertEntityCache(String entityName, SessionFactory sesFactory, Map<Integer, String> idToName,
+        Integer... absentIds) {
+        assert entityName.equals(ENTITY_NAME) || entityName.equals(ENTITY2_NAME) : entityName;
+
+        sesFactory.getStatistics().clear();
+
+        final Session ses = sesFactory.openSession();
+
+        final boolean entity1 = entityName.equals(ENTITY_NAME);
+
+        try {
+            if (entity1) {
+                for (Map.Entry<Integer, String> e : idToName.entrySet())
+                    assertEquals(e.getValue(), ((Entity)ses.load(Entity.class, e.getKey())).getName());
+            }
+            else {
+                for (Map.Entry<Integer, String> e : idToName.entrySet())
+                    assertEquals(e.getValue(), ((Entity2)ses.load(Entity2.class, e.getKey())).getName());
+            }
+
+            for (final int id : absentIds) {
+                GridTestUtils.assertThrows(log, new Callable<Void>() {
+                    @Override public Void call() throws Exception {
+                        if (entity1)
+                            ((Entity)ses.load(Entity.class, id)).getName();
+                        else
+                            ((Entity2)ses.load(Entity2.class, id)).getName();
+
+                        return null;
+                    }
+                }, ObjectNotFoundException.class, null);
+            }
+
+            SecondLevelCacheStatistics stats = sesFactory.getStatistics().getSecondLevelCacheStatistics(entityName);
+
+            assertEquals(idToName.size(), stats.getHitCount());
+
+            assertEquals(absentIds.length, stats.getMissCount());
+        }
+        finally {
+            ses.close();
+        }
+    }
+
+    /**
+     * Creates session factories.
+     *
+     * @param accessType Cache access type.
+     */
+    private void createSessionFactories(AccessType accessType) {
+        sesFactory1 = startHibernate(accessType, getTestIgniteInstanceName(0));
+
+        sesFactory2 = startHibernate(accessType, getTestIgniteInstanceName(1));
+    }
+
+    /**
+     * Starts Hibernate.
+     *
+     * @param accessType Cache access type.
+     * @param igniteInstanceName Ignite instance name.
+     * @return Session factory.
+     */
+    private SessionFactory startHibernate(org.hibernate.cache.spi.access.AccessType accessType, String igniteInstanceName) {
+        StandardServiceRegistryBuilder builder = registryBuilder();
+
+        for (Map.Entry<String, String> e : hibernateProperties(igniteInstanceName, accessType.name()).entrySet())
+            builder.applySetting(e.getKey(), e.getValue());
+
+        // Use the same cache for Entity and Entity2.
+        builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, ENTITY_NAME);
+
+        StandardServiceRegistry srvcRegistry = builder.build();
+
+        MetadataSources metadataSources = new MetadataSources(srvcRegistry);
+
+        for (Class entityClass : getAnnotatedClasses())
+            metadataSources.addAnnotatedClass(entityClass);
+
+        Metadata metadata = metadataSources.buildMetadata();
+
+        for (PersistentClass entityBinding : metadata.getEntityBindings()) {
+            if (!entityBinding.isInherited())
+                ((RootClass)entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
+        }
+
+        for (org.hibernate.mapping.Collection collectionBinding : metadata.getCollectionBindings())
+            collectionBinding.setCacheConcurrencyStrategy( accessType.getExternalName() );
+
+        return metadata.buildSessionFactory();
+    }
+
+    /**
+     * @return Entities classes.
+     */
+    private Class[] getAnnotatedClasses() {
+        return new Class[]{Entity.class, Entity2.class, VersionedEntity.class, ChildEntity.class, ParentEntity.class};
+    }
+
+    /**
+     * Closes session factories and clears data from caches.
+     *
+     * @throws Exception If failed.
+     */
+    private void cleanup() throws Exception {
+        if (sesFactory1 != null)
+            sesFactory1.close();
+
+        sesFactory1 = null;
+
+        if (sesFactory2 != null)
+            sesFactory2.close();
+
+        sesFactory2 = null;
+
+        for (IgniteCacheProxy<?, ?> cache : ((IgniteKernal)grid(0)).caches())
+            cache.clear();
+    }
+
+    /**
+     * @param igniteInstanceName Node name.
+     * @param dfltAccessType Default cache access type.
+     * @return Properties map.
+     */
+    static Map<String, String> hibernateProperties(String igniteInstanceName, String dfltAccessType) {
+        Map<String, String> map = new HashMap<>();
+
+        map.put(HBM2DDL_AUTO, "create");
+        map.put(GENERATE_STATISTICS, "true");
+        map.put(USE_SECOND_LEVEL_CACHE, "true");
+        map.put(USE_QUERY_CACHE, "true");
+        map.put(CACHE_REGION_FACTORY, HibernateRegionFactory.class.getName());
+        map.put(RELEASE_CONNECTIONS, "on_close");
+        map.put(IGNITE_INSTANCE_NAME_PROPERTY, igniteInstanceName);
+        map.put(DFLT_ACCESS_TYPE_PROPERTY, dfltAccessType);
+
+        return map;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalSelfTest.java b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalSelfTest.java
new file mode 100644
index 0000000..5175292
--- /dev/null
+++ b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalSelfTest.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import java.util.Collections;
+import javax.cache.configuration.Factory;
+import javax.transaction.Synchronization;
+import javax.transaction.TransactionManager;
+import javax.transaction.UserTransaction;
+import org.apache.commons.dbcp.managed.BasicManagedDataSource;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.h2.jdbcx.JdbcDataSource;
+import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
+import org.hibernate.cache.spi.access.AccessType;
+import org.hibernate.cfg.Environment;
+import org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl;
+import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
+import org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform;
+import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
+import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl;
+import org.jetbrains.annotations.Nullable;
+import org.objectweb.jotm.Jotm;
+
+/**
+ *
+ * Tests Hibernate L2 cache with TRANSACTIONAL access mode (Hibernate and Cache are configured
+ * to used the same TransactionManager).
+ */
+public class HibernateL2CacheTransactionalSelfTest extends HibernateL2CacheSelfTest {
+    /** */
+    private static Jotm jotm;
+
+    /**
+     */
+    private static class TestJtaPlatform extends AbstractJtaPlatform {
+        /** {@inheritDoc} */
+        @Override protected TransactionManager locateTransactionManager() {
+            return jotm.getTransactionManager();
+        }
+
+        /** {@inheritDoc} */
+        @Override protected UserTransaction locateUserTransaction() {
+            return jotm.getUserTransaction();
+        }
+    }
+
+    /**
+     */
+    @SuppressWarnings("PublicInnerClass")
+    public static class TestTmFactory implements Factory<TransactionManager> {
+        /** */
+        private static final long serialVersionUID = 0;
+
+        /** {@inheritDoc} */
+        @Override public TransactionManager create() {
+            return jotm.getTransactionManager();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        jotm = new Jotm(true, false);
+
+        super.beforeTestsStarted();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        super.afterTestsStopped();
+
+        if (jotm != null)
+            jotm.stop();
+
+        jotm = null;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        cfg.getTransactionConfiguration().setTxManagerFactory(new TestTmFactory());
+        cfg.getTransactionConfiguration().setUseJtaSynchronization(useJtaSynchronization());
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheConfiguration transactionalRegionConfiguration(String regionName) {
+        CacheConfiguration cfg = super.transactionalRegionConfiguration(regionName);
+
+        cfg.setNearConfiguration(null);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override protected StandardServiceRegistryBuilder registryBuilder() {
+        StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
+
+        DatasourceConnectionProviderImpl connProvider = new DatasourceConnectionProviderImpl();
+
+        BasicManagedDataSource dataSrc = new BasicManagedDataSource(); // JTA-aware data source.
+
+        dataSrc.setTransactionManager(jotm.getTransactionManager());
+
+        dataSrc.setDefaultAutoCommit(false);
+
+        JdbcDataSource h2DataSrc = new JdbcDataSource();
+
+        h2DataSrc.setURL(CONNECTION_URL);
+
+        dataSrc.setXaDataSourceInstance(h2DataSrc);
+
+        connProvider.setDataSource(dataSrc);
+
+        connProvider.configure(Collections.emptyMap());
+
+        builder.addService(ConnectionProvider.class, connProvider);
+
+        builder.addService(JtaPlatform.class, new TestJtaPlatform());
+
+        builder.applySetting(Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName());
+
+        return builder;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected AccessType[] accessTypes() {
+        return new AccessType[]{AccessType.TRANSACTIONAL};
+    }
+
+    /**
+     * @return Whether to use {@link Synchronization}.
+     */
+    protected boolean useJtaSynchronization() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalUseSyncSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalUseSyncSelfTest.java b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalUseSyncSelfTest.java
new file mode 100644
index 0000000..44899f9
--- /dev/null
+++ b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/hibernate/HibernateL2CacheTransactionalUseSyncSelfTest.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.hibernate;
+
+import javax.transaction.Synchronization;
+
+/**
+ * Tests Hibernate L2 cache with TRANSACTIONAL access mode and {@link Synchronization}
+ * instead of XA resource.
+ */
+public class HibernateL2CacheTransactionalUseSyncSelfTest extends HibernateL2CacheTransactionalSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean useJtaSynchronization() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreNodeRestartTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreNodeRestartTest.java b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreNodeRestartTest.java
new file mode 100644
index 0000000..d5496af
--- /dev/null
+++ b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreNodeRestartTest.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.store.hibernate;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.store.CacheStore;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.integration.IgniteCacheStoreNodeRestartAbstractTest;
+
+public class CacheHibernateBlobStoreNodeRestartTest extends IgniteCacheStoreNodeRestartAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected CacheStore getStore() {
+        return new CacheHibernateBlobStore();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return CacheMode.PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return CacheAtomicityMode.ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return null;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreSelfTest.java b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreSelfTest.java
new file mode 100644
index 0000000..c62db4a
--- /dev/null
+++ b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateBlobStoreSelfTest.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.store.hibernate;
+
+import java.io.File;
+import java.net.URL;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.junits.cache.GridAbstractCacheStoreSelfTest;
+import org.hibernate.FlushMode;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.resource.transaction.spi.TransactionStatus;
+
+/**
+ * Cache store test.
+ */
+public class CacheHibernateBlobStoreSelfTest extends
+    GridAbstractCacheStoreSelfTest<CacheHibernateBlobStore<Object, Object>> {
+    /**
+     * @throws Exception If failed.
+     */
+    public CacheHibernateBlobStoreSelfTest() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        Session s = store.session(null);
+
+        if (s == null)
+            return;
+
+        try {
+            s.createQuery("delete from " + CacheHibernateBlobStoreEntry.class.getSimpleName())
+                    .setFlushMode(FlushMode.ALWAYS).executeUpdate();
+
+            Transaction hTx = s.getTransaction();
+
+            if (hTx != null && hTx.getStatus() == TransactionStatus.ACTIVE)
+                hTx.commit();
+        }
+        finally {
+            s.close();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheHibernateBlobStore<Object, Object> store() {
+        return new CacheHibernateBlobStore<>();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testConfigurationByUrl() throws Exception {
+        URL url = U.resolveIgniteUrl(CacheHibernateStoreFactorySelfTest.MODULE_PATH +
+            "/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml");
+
+        assert url != null;
+
+        store.setHibernateConfigurationPath(url.toString());
+
+        // Store will be implicitly initialized.
+        store.load("key");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testConfigurationByFile() throws Exception {
+        URL url = U.resolveIgniteUrl(CacheHibernateStoreFactorySelfTest.MODULE_PATH +
+                "/src/test/java/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml");
+
+        assert url != null;
+
+        File file = new File(url.toURI());
+
+        store.setHibernateConfigurationPath(file.getAbsolutePath());
+
+        // Store will be implicitly initialized.
+        store.load("key");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testConfigurationByResource() throws Exception {
+        store.setHibernateConfigurationPath("/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml");
+
+        // Store will be implicitly initialized.
+        store.load("key");
+    }
+
+    @Override public void testSimpleMultithreading() throws Exception {
+        fail("https://issues.apache.org/jira/browse/IGNITE-1757");
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/ee1b19d3/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreFactorySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreFactorySelfTest.java b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreFactorySelfTest.java
new file mode 100644
index 0000000..7d4f280
--- /dev/null
+++ b/modules/hibernate-5.1/src/test/java/org/apache/ignite/cache/store/hibernate/CacheHibernateStoreFactorySelfTest.java
@@ -0,0 +1,256 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.store.hibernate;
+
+import java.sql.Connection;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.hibernate.Cache;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.SessionBuilder;
+import org.hibernate.SessionFactory;
+import org.hibernate.StatelessSession;
+import org.hibernate.StatelessSessionBuilder;
+import org.hibernate.TypeHelper;
+import org.hibernate.boot.spi.SessionFactoryOptions;
+import org.hibernate.engine.spi.FilterDefinition;
+import org.hibernate.metadata.ClassMetadata;
+import org.hibernate.metadata.CollectionMetadata;
+import org.hibernate.stat.Statistics;
+
+/**
+ * Test for Cache jdbc blob store factory.
+ */
+public class CacheHibernateStoreFactorySelfTest extends GridCommonAbstractTest {
+    /** Cache name. */
+    private static final String CACHE_NAME = "test";
+
+    /** */
+    static final String MODULE_PATH = "modules/hibernate-5.1/";
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCacheConfiguration() throws Exception {
+        try (Ignite ignite1 = startGrid(0)) {
+            IgniteCache<Integer, String> cache1 = ignite1.getOrCreateCache(cacheConfiguration());
+
+            checkStore(cache1);
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testXmlConfiguration() throws Exception {
+        try (Ignite ignite = Ignition.start(MODULE_PATH + "/src/test/config/factory-cache.xml")) {
+            try(Ignite ignite1 = Ignition.start(MODULE_PATH + "/src/test/config/factory-cache1.xml")) {
+                checkStore(ignite.<Integer, String>cache(CACHE_NAME), DummySessionFactoryExt.class);
+
+                checkStore(ignite1.<Integer, String>cache(CACHE_NAME), DummySessionFactory.class);
+            }
+        }
+    }
+
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testIncorrectBeanConfiguration() throws Exception {
+        GridTestUtils.assertThrows(log, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                try(Ignite ignite =
+                    Ignition.start(MODULE_PATH + "/src/test/config/factory-incorrect-store-cache.xml")) {
+                    ignite.cache(CACHE_NAME).getConfiguration(CacheConfiguration.class).
+                            getCacheStoreFactory().create();
+                }
+                return null;
+            }
+        }, IgniteException.class, "Failed to load bean in application context");
+    }
+
+    /**
+     * @return Cache configuration with store.
+     */
+    private CacheConfiguration<Integer, String> cacheConfiguration() {
+        CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>();
+
+        CacheHibernateBlobStoreFactory<Integer, String> factory = new CacheHibernateBlobStoreFactory();
+
+        factory.setHibernateConfigurationPath("/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml");
+
+        cfg.setCacheStoreFactory(factory);
+
+        return cfg;
+    }
+
+    /**
+     * @param cache Ignite cache.
+     * @param dataSrcClass Data source class.
+     * @throws Exception If store parameters is not the same as in configuration xml.
+     */
+    private void checkStore(IgniteCache<Integer, String> cache, Class<?> dataSrcClass) throws Exception {
+        CacheHibernateBlobStore store = (CacheHibernateBlobStore)cache
+            .getConfiguration(CacheConfiguration.class).getCacheStoreFactory().create();
+
+        assertEquals(dataSrcClass,
+            GridTestUtils.getFieldValue(store, CacheHibernateBlobStore.class, "sesFactory").getClass());
+    }
+
+    /**
+     * @param cache Ignite cache.
+     * @throws Exception If store parameters is not the same as in configuration xml.
+     */
+    private void checkStore(IgniteCache<Integer, String> cache) throws Exception {
+        CacheHibernateBlobStore store = (CacheHibernateBlobStore)cache.getConfiguration(CacheConfiguration.class)
+            .getCacheStoreFactory().create();
+
+        assertEquals("/org/apache/ignite/cache/store/hibernate/hibernate.cfg.xml",
+            GridTestUtils.getFieldValue(store, CacheHibernateBlobStore.class, "hibernateCfgPath"));
+    }
+
+    /**
+     *
+     */
+    public static class DummySessionFactoryExt extends DummySessionFactory {
+        /** */
+        public DummySessionFactoryExt() {
+            // No-op.
+        }
+    }
+
+    /**
+     *
+     */
+    public static class DummySessionFactory implements SessionFactory {
+        /** {@inheritDoc} */
+        @Override public SessionFactoryOptions getSessionFactoryOptions() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public SessionBuilder withOptions() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Session openSession() throws HibernateException {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Session getCurrentSession() throws HibernateException {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public StatelessSessionBuilder withStatelessOptions() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public StatelessSession openStatelessSession() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public StatelessSession openStatelessSession(Connection conn) {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public ClassMetadata getClassMetadata(Class entityCls) {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public ClassMetadata getClassMetadata(String entityName) {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public CollectionMetadata getCollectionMetadata(String roleName) {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Map<String, ClassMetadata> getAllClassMetadata() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Map getAllCollectionMetadata() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Statistics getStatistics() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void close() throws HibernateException {
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean isClosed() {
+            return false;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Cache getCache() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Set getDefinedFilterNames() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public FilterDefinition getFilterDefinition(String filterName) throws HibernateException {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean containsFetchProfileDefinition(String name) {
+            return false;
+        }
+
+        /** {@inheritDoc} */
+        @Override public TypeHelper getTypeHelper() {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Reference getReference() throws NamingException {
+            return null;
+        }
+    }
+}
\ No newline at end of file