blob: 95d75599ce76fce120ccd38c39eec0a49e944493 [file] [log] [blame]
<!--
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 html>
<html lang="en">
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-1382082-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-61232409-1');
</script>
<meta charset="UTF-8">
<title>Apache Ignite With Spring Data | Ignite Documentation</title>
<link rel="canonical" href="/docs/spring/spring-data" />
<link rel="stylesheet" href="/assets/css/styles.css?1651672546">
<link rel="stylesheet" href="/assets/css/asciidoc-pygments.css">
<link rel="shortcut icon" href="/favicon.ico">
<meta name='viewport' content='width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0'>
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="/assets/js/jquery.swiftype.autocomplete.js?1651672546"></script>
<script type="text/javascript" src="/assets/js/anchor.min.js?1651672546"></script>
</head>
<body>
<!--
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.
-->
<header>
<div class="container">
<button type='button' class='menu' title='Docs menu'>
<img src="/assets/images/menu-icon.svg"/>
</button>
<div class='home'>
<a href="/" class='home' title='Apache Ignite home'>
<img src="/assets/images/apache_ignite_logo.svg" alt="Apache Ignite logo" width="103" height="36" >
</a>
</div>
<nav>
</nav>
<form class='search'>
<button class="search-close" type='button'><img src='/assets/images/cancel.svg'></button>
<input type="search" placeholder="Search…" id="search-input">
</form>
<button type='button' class='search-toggle'><img src='/assets/images/search.svg'></button>
<button type='button' class='top-nav-toggle'></button>
<a href="https://github.com/ignite" title='GitHub' class='github' target="_blank">
<img src="/assets/images/github-gray.svg" alt="GitHub logo">
</a>
</div>
</header>
<!--
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.
-->
<link rel="stylesheet" href="/assets/css/docs.css">
<section class='page-docs'>
<!--
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.
-->
<nav class='left-nav' data-swiftype-index='false'>
<li>
<a href="/docs/extensions/aws/aws" class='' >Amazon S3 IP Finder</a>
</li>
<li>
<a href="/docs/extensions/camel/camel-streamer" class='' >Apache Camel Streamer</a>
</li>
<li>
<a href="/docs/extensions/flink/flink-streamer" class='' >Apache Flink Streamer</a>
</li>
<li>
<a href="/docs/extensions/flume/flume-sink" class='' >Apache Flume Sink</a>
</li>
<li>
<a href="/docs/extensions/azure/azure" class='' >Apache Ignite Azure Module</a>
</li>
<li>
<a href="/docs/extensions/gce/gce" class='' >Apache Ignite GCE Module</a>
</li>
<li>
<a href="/docs/extensions/pub-sub/pub-sub" class='' >Apache Ignite Pub/Sub Module</a>
</li>
<li>
<a href="/docs/extensions/spring/spring-boot" class='' >Apache Ignite and Spring Boot</a>
</li>
<li>
<a href="/docs/extensions/spring/spring-data" class='' >Apache Ignite and Spring Data</a>
</li>
<li>
<a href="/docs/extensions/spring/spring-caching" class='' >Apache Ignite and Spring Cache</a>
</li>
<li>
<a href="/docs/extensions/spring/spring-tx" class='' >Apache Ignite and Spring Transactions</a>
</li>
<li>
<a href="/docs/extensions/kafka/kafka-streamer" class='' >Apache Kafka Streamer</a>
</li>
<li>
<a href="/docs/extensions/storm/storm-streamer" class='' >Apache Storm Streamer</a>
</li>
<li>
<a href="/docs/extensions/cdc/change-data-capture-extensions" class='' >Change Data Capture Extension</a>
</li>
<li>
<a href="/docs/extensions/jms/jms-streamer" class='' >JMS Streamer</a>
</li>
<li>
<a href="/docs/extensions/mqtt/mqtt-streamer" class='' >MQTT Streamer</a>
</li>
<li>
<a href="/docs/extensions/perf-statistics/performance-statistics" class='' >Performance Statistics Extension</a>
</li>
<li>
<a href="/docs/extensions/rocketmq/rocketmq-streamer" class='' >RocketMQ Streamer</a>
</li>
<li>
<a href="/docs/extensions/topology-validator/topology-validator" class='' >Topology Validator</a>
</li>
<li>
<a href="/docs/extensions/twitter/twitter-streamer" class='' >Twitter Streamer</a>
</li>
<li>
<a href="/docs/extensions/zeromq/zeromq-streamer" class='' >ZeroMQ Streamer</a>
</li>
<li>
<a href="/docs/extensions/zookeeper/zookeeper-ip" class='' >ZooKeeper IP Finder</a>
</li>
</nav>
<div class="left-nav__overlay"></div>
<article data-swiftype-index='true'>
<a class='edit-link' href="/_docs/spring/spring-data.adoc" target="_blank">Edit</a>
<h1>Apache Ignite With Spring Data</h1>
<div class="sect1">
<h2 id="overview">Overview</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Spring Data Framework provides a unified and widely used API that allows abstracting an underlying data storage from the
application layer. Spring Data helps you avoid locking to a specific database vendor, making it easy to switch from one
database to another with minimal efforts. Apache Ignite integrates with Spring Data by implementing Spring Data <code>CrudRepository</code> interface.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="maven-configuration">Maven Configuration</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The easiest way to start working with Apache Ignite&#8217;s Spring Data repository is by adding the following Maven dependencies
to the application&#8217;s <code>pom.xml</code> file:</p>
</div>
<code-tabs><code-tab data-tab='pom.xml'><div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="xml"><span class="nt">&lt;dependency&gt;</span>
<span class="nt">&lt;groupId&gt;</span>org.apache.ignite<span class="nt">&lt;/groupId&gt;</span>
<span class="nt">&lt;artifactId&gt;</span>ignite-spring-data-2.2-ext<span class="nt">&lt;/artifactId&gt;</span>
<span class="nt">&lt;version&gt;</span>${ignite-spring-data-ext.version}<span class="nt">&lt;/version&gt;</span>
<span class="nt">&lt;/dependency&gt;</span>
<span class="nt">&lt;dependency&gt;</span>
<span class="nt">&lt;groupId&gt;</span>org.apache.ignite<span class="nt">&lt;/groupId&gt;</span>
<span class="nt">&lt;artifactId&gt;</span>ignite-core<span class="nt">&lt;/artifactId&gt;</span>
<span class="nt">&lt;version&gt;</span>${ignite.version}<span class="nt">&lt;/version&gt;</span>
<span class="nt">&lt;/dependency&gt;</span>
<span class="nt">&lt;dependency&gt;</span>
<span class="nt">&lt;groupId&gt;</span>org.apache.ignite<span class="nt">&lt;/groupId&gt;</span>
<span class="nt">&lt;artifactId&gt;</span>ignite-indexing<span class="nt">&lt;/artifactId&gt;</span>
<span class="nt">&lt;version&gt;</span>${ignite.version}<span class="nt">&lt;/version&gt;</span>
<span class="nt">&lt;/dependency&gt;</span>
<span class="nt">&lt;dependency&gt;</span>
<span class="nt">&lt;groupId&gt;</span>org.apache.ignite<span class="nt">&lt;/groupId&gt;</span>
<span class="nt">&lt;artifactId&gt;</span>ignite-spring<span class="nt">&lt;/artifactId&gt;</span>
<span class="nt">&lt;version&gt;</span>${ignite.version}<span class="nt">&lt;/version&gt;</span>
<span class="nt">&lt;/dependency&gt;</span>
<span class="nt">&lt;dependency&gt;</span>
<span class="nt">&lt;groupId&gt;</span>org.springframework.data<span class="nt">&lt;/groupId&gt;</span>
<span class="nt">&lt;artifactId&gt;</span>spring-data-commons<span class="nt">&lt;/artifactId&gt;</span>
<span class="nt">&lt;version&gt;</span>${spring.data.version}<span class="nt">&lt;/version&gt;</span>
<span class="nt">&lt;/dependency&gt;</span></code></pre>
</div>
</div></code-tab></code-tabs>
<div class="paragraph">
<p>Replace <code>${ignite-spring-data-ext.version}</code>, <code>${spring.data.version}</code>, and
<code>${ignite.version}</code> with an actual version of Apache Ignite Spring Data extension, Spring Data, and Apache Ignite
dependencies you are interested in, respectively.</p>
</div>
<div class="paragraph">
<p>The table below shows available versions of the Apache Ignite Spring Data extension and corresponding versions of the
Apache Ignite each one is compatible with.</p>
</div>
<table class="tableblock frame-all grid-all stripes-even stretch">
<colgroup>
<col style="width: 44.4444%;">
<col style="width: 55.5556%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Apache Ignite Spring Data extension version</th>
<th class="tableblock halign-left valign-top">Compatible Apache Ignite versions</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.0.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">All versions since 2.8.0</p></td>
</tr>
</tbody>
</table>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<div class="title">Note</div>
</td>
<td class="content">
<div class="paragraph">
<p>If your Spring Data version is earlier than Spring Data 2.2 then set <code>ignite-spring-data-2.0-ext</code>
or <code>ignite-spring-data-ext</code> as an <code>artifactId</code> in the pom.xml configuration.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="apache-ignite-repository">Apache Ignite Repository</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Apache Ignite introduces a special <code>IgniteRepository</code> interface that extends default <code>CrudRepository</code>. This interface
should be extended by all custom Spring Data repositories that wish to store and query data located in an Apache Ignite cluster.</p>
</div>
<div class="paragraph">
<p>For instance, let&#8217;s create the first custom repository named <code>PersonRepository</code>:</p>
</div>
<code-tabs><code-tab data-tab='Java'><div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="java"><span class="nd">@RepositoryConfig</span><span class="o">(</span><span class="n">cacheName</span> <span class="o">=</span> <span class="s">"PersonCache"</span><span class="o">)</span>
<span class="kd">public</span> <span class="kd">interface</span> <span class="nc">PersonRepository</span> <span class="kd">extends</span> <span class="nc">IgniteRepository</span><span class="o">&lt;</span><span class="nc">Person</span><span class="o">,</span> <span class="nc">Long</span><span class="o">&gt;</span> <span class="o">{</span>
<span class="cm">/**
* Gets all the persons with the given name.
* @param name Person name.
* @return A list of Persons with the given first name.
*/</span>
<span class="kd">public</span> <span class="nc">List</span><span class="o">&lt;</span><span class="nc">Person</span><span class="o">&gt;</span> <span class="nf">findByFirstName</span><span class="o">(</span><span class="nc">String</span> <span class="n">name</span><span class="o">);</span>
<span class="cm">/**
* Returns top Person with the specified surname.
* @param name Person surname.
* @return Person that satisfy the query.
*/</span>
<span class="kd">public</span> <span class="nc">Cache</span><span class="o">.</span><span class="na">Entry</span><span class="o">&lt;</span><span class="nc">Long</span><span class="o">,</span> <span class="nc">Person</span><span class="o">&gt;</span> <span class="nf">findTopByLastNameLike</span><span class="o">(</span><span class="nc">String</span> <span class="n">name</span><span class="o">);</span>
<span class="cm">/**
* Getting ids of all the Person satisfying the custom query from {@link Query} annotation.
*
* @param orgId Query parameter.
* @param pageable Pageable interface.
* @return A list of Persons' ids.
*/</span>
<span class="nd">@Query</span><span class="o">(</span><span class="s">"SELECT id FROM Person WHERE orgId &gt; ?"</span><span class="o">)</span>
<span class="kd">public</span> <span class="nc">List</span><span class="o">&lt;</span><span class="nc">Long</span><span class="o">&gt;</span> <span class="nf">selectId</span><span class="o">(</span><span class="kt">long</span> <span class="n">orgId</span><span class="o">,</span> <span class="nc">Pageable</span> <span class="n">pageable</span><span class="o">);</span>
<span class="o">}</span></code></pre>
</div>
</div></code-tab></code-tabs>
<div class="ulist">
<ul>
<li>
<p><code>@RepositoryConfig</code> annotation should be specified to map a repository to a distributed cache. In the above example, <code>PersonRepository</code> is mapped to <code>PersonCache</code>.</p>
</li>
<li>
<p>Signatures of custom methods like <code>findByFirstName(name)</code> and <code>findTopByLastNameLike(name)</code> will be automatically processed and turned
into SQL queries when methods get executed. In addition, <code>@Query(queryString)</code> annotation can be used if a concrete​ SQL
query needs to be executed as a result of a method call.</p>
</li>
</ul>
</div>
<div class="admonitionblock caution">
<table>
<tr>
<td class="icon">
<div class="title">Caution</div>
</td>
<td class="content">
<h3 id="unsupported-crud-operations" class="discrete">Unsupported CRUD Operations</h3>
<div class="paragraph">
<p>Some operations of CrudRepository interface are not currently supported. These are the operations that do not require providing the key as a parameter:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>save(S entity)</p>
</li>
<li>
<p>save(Iterable&lt;S&gt; entities)</p>
</li>
<li>
<p>delete(T entity)</p>
</li>
<li>
<p>delete(Iterable&lt;? extends T&gt; entities)</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Instead of these operations you can use Ignite specific counterparts available via <code>IgniteRepository</code> interface:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>save(ID key, S entity)</p>
</li>
<li>
<p>save(Map&lt;ID, S&gt; entities)</p>
</li>
<li>
<p>deleteAll(Iterable&lt;ID&gt; ids)</p>
</li>
</ul>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="spring-data-and-apache-ignite-configuration">Spring Data and Apache Ignite Configuration</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Apache Ignite Spring Data integration supports connecting to the Apache Ignite cluster through the Apache Ignite node or
Apache Ignite thin client. Both approaches to configuring access to the Apache Ignite cluster use the same API shown
below. Apache Ignite Spring Data integration automatically recognizes the type of the provided bean and uses the
appropriate cluster connection.</p>
</div>
<div class="paragraph">
<p>To enable Apache Ignite backed repositories in Spring Data, mark an application configuration with <code>@EnableIgniteRepositories</code>
annotation, as shown below:</p>
</div>
<code-tabs><code-tab data-tab='Ignite node connection configuration'><div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="java"><span class="nd">@Configuration</span>
<span class="nd">@EnableIgniteRepositories</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">SpringAppCfg</span> <span class="o">{</span>
<span class="cm">/**
* Creating Apache Ignite instance bean. A bean will be passed
* to IgniteRepositoryFactoryBean to initialize all Ignite based Spring Data repositories and connect to a cluster.
*/</span>
<span class="nd">@Bean</span>
<span class="kd">public</span> <span class="nc">Ignite</span> <span class="nf">igniteInstance</span><span class="o">()</span> <span class="o">{</span>
<span class="nc">IgniteConfiguration</span> <span class="n">cfg</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">IgniteConfiguration</span><span class="o">();</span>
<span class="c1">// Setting some custom name for the node.</span>
<span class="n">cfg</span><span class="o">.</span><span class="na">setIgniteInstanceName</span><span class="o">(</span><span class="s">"springDataNode"</span><span class="o">);</span>
<span class="c1">// Enabling peer-class loading feature.</span>
<span class="n">cfg</span><span class="o">.</span><span class="na">setPeerClassLoadingEnabled</span><span class="o">(</span><span class="kc">true</span><span class="o">);</span>
<span class="c1">// Defining and creating a new cache to be used by Ignite Spring Data</span>
<span class="c1">// repository.</span>
<span class="nc">CacheConfiguration</span> <span class="n">ccfg</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">CacheConfiguration</span><span class="o">(</span><span class="s">"PersonCache"</span><span class="o">);</span>
<span class="c1">// Setting SQL schema for the cache.</span>
<span class="n">ccfg</span><span class="o">.</span><span class="na">setIndexedTypes</span><span class="o">(</span><span class="nc">Long</span><span class="o">.</span><span class="na">class</span><span class="o">,</span> <span class="nc">Person</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
<span class="n">cfg</span><span class="o">.</span><span class="na">setCacheConfiguration</span><span class="o">(</span><span class="n">ccfg</span><span class="o">);</span>
<span class="k">return</span> <span class="nc">Ignition</span><span class="o">.</span><span class="na">start</span><span class="o">(</span><span class="n">cfg</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span></code></pre>
</div>
</div></code-tab><code-tab data-tab='Ignite thin client connection configuration'><div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="java"><span class="nd">@Configuration</span>
<span class="nd">@EnableIgniteRepositories</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="nc">SpringAppCfg</span> <span class="o">{</span>
<span class="cm">/**
* Creating Apache Ignite thin client instance bean. A bean will be passed to the IgniteRepositoryFactoryBean to
* connect to the Ignite cluster and perform cache operations.
*/</span>
<span class="nd">@Bean</span>
<span class="kd">public</span> <span class="nc">IgniteClient</span> <span class="nf">igniteInstance</span><span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="nc">Ignition</span><span class="o">.</span><span class="na">startClient</span><span class="o">(</span><span class="k">new</span> <span class="nc">ClientConfiguration</span><span class="o">().</span><span class="na">setAddresses</span><span class="o">(</span><span class="s">"127.0.0.1:10800"</span><span class="o">);;</span>
<span class="o">}</span>
<span class="o">}</span></code></pre>
</div>
</div></code-tab></code-tabs>
<div class="paragraph">
<p>The configuration has to instantiate the Apache Ignite bean (node) or the Apache Ignite thin client bean that is passed
to <code>IgniteRepositoryFactoryBean</code> and is used by all the Apache Ignite repositories in order to connect to the cluster.</p>
</div>
<div class="paragraph">
<p>In the example above, the bean is initialized directly by the application and is named <code>igniteInstance</code>.
Alternatively, the following beans can be registered in your configuration and an Apache Ignite node will be started automatically:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>IgniteConfiguration</code> object named as <code>igniteCfg</code> bean.</p>
</li>
<li>
<p>A path to Apache Ignite&#8217;s Spring XML configuration named <code>igniteSpringCfgPath</code>.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>In the case of connecting to the cluster via Apache Ignite thin client, you can alternatively register the
<code>ClientConfiguration</code> bean named <code>igniteCfg</code>, so that the Apache Ignite thin client instance is started automatically by
the Apache Ignite Spring Data integration.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="using-apache-ignite-repositories">Using Apache Ignite Repositories</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Once all the configurations and repositories are ready to be used, you can register the configuration in an application context and get a reference to the repository.
The following example shows how to register <code>SpringAppCfg</code> - our sample configuration from the section above - in an application context and get a reference to <code>PersonRepository</code>:</p>
</div>
<code-tabs><code-tab data-tab='Java'><div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="java"><span class="n">ctx</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">AnnotationConfigApplicationContext</span><span class="o">();</span>
<span class="c1">// Explicitly registering Spring configuration.</span>
<span class="n">ctx</span><span class="o">.</span><span class="na">register</span><span class="o">(</span><span class="nc">SpringAppCfg</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
<span class="n">ctx</span><span class="o">.</span><span class="na">refresh</span><span class="o">();</span>
<span class="c1">// Getting a reference to PersonRepository.</span>
<span class="n">repo</span> <span class="o">=</span> <span class="n">ctx</span><span class="o">.</span><span class="na">getBean</span><span class="o">(</span><span class="nc">PersonRepository</span><span class="o">.</span><span class="na">class</span><span class="o">);</span></code></pre>
</div>
</div></code-tab></code-tabs>
<div class="paragraph">
<p>Now, you can put data in Ignite using Spring Data API:</p>
</div>
<code-tabs><code-tab data-tab='Java'><div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="java"><span class="nc">TreeMap</span><span class="o">&lt;</span><span class="nc">Long</span><span class="o">,</span> <span class="nc">Person</span><span class="o">&gt;</span> <span class="n">persons</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">TreeMap</span><span class="o">&lt;&gt;();</span>
<span class="n">persons</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="mi">1L</span><span class="o">,</span> <span class="k">new</span> <span class="nc">Person</span><span class="o">(</span><span class="mi">1L</span><span class="o">,</span> <span class="mi">2000L</span><span class="o">,</span> <span class="s">"John"</span><span class="o">,</span> <span class="s">"Smith"</span><span class="o">,</span> <span class="mi">15000</span><span class="o">,</span> <span class="s">"Worked for Apple"</span><span class="o">));</span>
<span class="n">persons</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="mi">2L</span><span class="o">,</span> <span class="k">new</span> <span class="nc">Person</span><span class="o">(</span><span class="mi">2L</span><span class="o">,</span> <span class="mi">2000L</span><span class="o">,</span> <span class="s">"Brad"</span><span class="o">,</span> <span class="s">"Pitt"</span><span class="o">,</span> <span class="mi">16000</span><span class="o">,</span> <span class="s">"Worked for Oracle"</span><span class="o">));</span>
<span class="n">persons</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="mi">3L</span><span class="o">,</span> <span class="k">new</span> <span class="nc">Person</span><span class="o">(</span><span class="mi">3L</span><span class="o">,</span> <span class="mi">1000L</span><span class="o">,</span> <span class="s">"Mark"</span><span class="o">,</span> <span class="s">"Tomson"</span><span class="o">,</span> <span class="mi">10000</span><span class="o">,</span> <span class="s">"Worked for Sun"</span><span class="o">));</span>
<span class="c1">// Adding data into the repository.</span>
<span class="n">repo</span><span class="o">.</span><span class="na">save</span><span class="o">(</span><span class="n">persons</span><span class="o">);</span></code></pre>
</div>
</div></code-tab></code-tabs>
<div class="paragraph">
<p>To query the data, we can use basic CRUD operations or methods that will be automatically turned into Apache Ignite SQL queries:</p>
</div>
<code-tabs><code-tab data-tab='Java'><div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="java"><span class="nc">List</span><span class="o">&lt;</span><span class="nc">Person</span><span class="o">&gt;</span> <span class="n">persons</span> <span class="o">=</span> <span class="n">repo</span><span class="o">.</span><span class="na">findByFirstName</span><span class="o">(</span><span class="s">"John"</span><span class="o">);</span>
<span class="k">for</span> <span class="o">(</span><span class="nc">Person</span> <span class="nl">person:</span> <span class="n">persons</span><span class="o">)</span>
<span class="nc">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">" &gt;&gt;&gt; "</span> <span class="o">+</span> <span class="n">person</span><span class="o">);</span>
<span class="nc">Cache</span><span class="o">.</span><span class="na">Entry</span><span class="o">&lt;</span><span class="nc">Long</span><span class="o">,</span> <span class="nc">Person</span><span class="o">&gt;</span> <span class="n">topPerson</span> <span class="o">=</span> <span class="n">repo</span><span class="o">.</span><span class="na">findTopByLastNameLike</span><span class="o">(</span><span class="s">"Smith"</span><span class="o">);</span>
<span class="nc">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">"\n&gt;&gt;&gt; Top Person with surname 'Smith': "</span> <span class="o">+</span>
<span class="n">topPerson</span><span class="o">.</span><span class="na">getValue</span><span class="o">());</span></code></pre>
</div>
</div></code-tab></code-tabs>
</div>
</div>
<div class="sect1">
<h2 id="example">Example</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The complete example is available on link: <a href="https://github.com/apache/ignite-extensions/tree/master/modules/spring-data-2.0-ext/examples/main">GitHub</a></p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="tutorial">Tutorial</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Follow the tutorial that shows how to build a <a href="https://www.gridgain.com/docs/tutorials/spring/spring-ignite-tutorial" target="_blank" rel="noopener">RESTful web service with Apache Ignite and Spring Data</a>.</p>
</div>
</div>
</div>
<!--
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.
-->
<div class="copyright">
© 2022 The Apache Software Foundation.<br/>
Apache, Apache Ignite, the Apache feather and the Apache Ignite logo are either registered trademarks or trademarks of The Apache Software Foundation.
</div>
</article>
<!--
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.
-->
<nav class="right-nav" data-swiftype-index='false'>
<ul class="sectlevel1">
<li><a href="#overview">Overview</a></li>
<li><a href="#maven-configuration">Maven Configuration</a></li>
<li><a href="#apache-ignite-repository">Apache Ignite Repository</a></li>
<li><a href="#spring-data-and-apache-ignite-configuration">Spring Data and Apache Ignite Configuration</a></li>
<li><a href="#using-apache-ignite-repositories">Using Apache Ignite Repositories</a></li>
<li><a href="#example">Example</a></li>
<li><a href="#tutorial">Tutorial</a></li>
</ul>
<!--
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.
-->
<footer>
</footer>
</nav>
</section>
<script type='module' src='/assets/js/code-copy-to-clipboard.js' async></script>
<script>
// inits deep anchors -- needs to be done here because of https://www.bryanbraun.com/anchorjs/#dont-run-it-too-late
anchors.add('.page-docs h1, .page-docs h2, .page-docs h3:not(.discrete), .page-docs h4, .page-docs h5');
anchors.options = {
placement: 'right',
visible: 'always'
};
</script>
</body>
<script type='module' src='/assets/js/index.js?1651672546' async></script>
</html>