{"id":12996,"date":"2013-05-23T16:00:34","date_gmt":"2013-05-23T13:00:34","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=12996"},"modified":"2013-05-22T11:34:13","modified_gmt":"2013-05-22T08:34:13","slug":"spring-data-solr-tutorial-crud-almost","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2013\/05\/spring-data-solr-tutorial-crud-almost.html","title":{"rendered":"Spring Data Solr Tutorial: CRUD (Almost)"},"content":{"rendered":"<p>In the <a href=\"http:\/\/www.petrikainulainen.net\/programming\/solr\/spring-data-solr-tutorial-configuration\/\">previous part<\/a> of my Spring Data Solr tutorial, we learned how we can configure Spring Data Solr. Now it is time to take a step forward and learn how we can manage the information stored in our Solr instance. This blog entry describes how we add new documents to the Solr index, update the information of existing documents and delete documents from the index.<\/p>\n<p>We can make the necessary modifications to our <a href=\"https:\/\/github.com\/pkainulainen\/spring-data-solr-examples\/tree\/master\/query-methods\" target=\"_blank\">example application<\/a> by following these steps:<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<\/p>\n<ol>\n<li>Create a document class which contains the information stored in the Solr index.<\/li>\n<li>Create a repository interface for our Spring Data Solr repository.<\/li>\n<li>Create a service which uses the created repository.<\/li>\n<li>Use the created service.<\/li>\n<\/ol>\n<p>These steps are described with more details in the following sections.<\/p>\n<p><strong>Note<\/strong>: These blog entries provide additional information which helps us to understand the concepts described in this blog entry:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.petrikainulainen.net\/programming\/maven\/running-solr-with-maven\/\">Running Solr with Maven<\/a><\/li>\n<li><a href=\"http:\/\/www.petrikainulainen.net\/programming\/solr\/spring-data-solr-tutorial-introduction-to-solr\/\">Spring Data Solr Tutorial: Introduction to Solr<\/a><\/li>\n<li><a href=\"http:\/\/www.petrikainulainen.net\/programming\/solr\/spring-data-solr-tutorial-configuration\/\">Spring Data Solr Tutorial: Configuration<\/a><\/li>\n<\/ul>\n<h2>Creating the Document Class<\/h2>\n<p>The first step is to create a document class which contains the information added to the Solr index. A document class is basically just a POJO which is implemented by following these rules:<\/p>\n<ul>\n<li>The <em>@Field<\/em> annotation is used to create a link between the fields of the POJO and the fields of the Solr document.<\/li>\n<li>If the name of the bean\u2019s field is not equal to the name of the document\u2019s field, the name of the document\u2019s field must be given as a value of the <em>@Field<\/em> annotation.<\/li>\n<li>The <em>@Field<\/em> annotation can be applied either to a field or setter method.<\/li>\n<li>Spring Data Solr assumes by default that the name of the document\u2019s id field is \u2018id\u2019. We can override this setting by annotating the id field with the <a href=\"http:\/\/static.springsource.org\/spring-data\/commons\/docs\/current\/api\/org\/springframework\/data\/annotation\/Id.html\" target=\"_blank\"><em>@Id<\/em><\/a> annotation.<\/li>\n<li>Spring Data Solr (version 1.0.0.RC1) requires that the type of the document\u2019s id is <em>String<\/em>.<\/li>\n<\/ul>\n<p><strong>More information<\/strong>:<\/p>\n<ul>\n<li><a href=\"http:\/\/wiki.apache.org\/solr\/Solrj#Directly_adding_POJOs_to_Solr\" target=\"_blank\">Solrj @ Solr Wiki<\/a><\/li>\n<\/ul>\n<p>Let\u2019s move on and create our document class.<\/p>\n<p>In the <a href=\"http:\/\/www.petrikainulainen.net\/programming\/solr\/spring-data-solr-tutorial-introduction-to-solr\/\">first part<\/a> of my Spring Data Solr tutorial, we learned that we have to store the <em>id<\/em>, <em>description<\/em> and <em>title<\/em> of each todo entry to the Solr index.<\/p>\n<p>Thus, we can create a document class for todo entries by following these steps:<\/p>\n<ol>\n<li>Create a class called <em>TodoDocument<\/em>.<\/li>\n<li>Add the <em>id<\/em> field to the <em>TodoDocument<\/em> class and annotate the field with the <em>@Field<\/em> annotation. Annotate the field with the @Id annotation (This is not required since the name of the id field is \u2018id\u2019 but I wanted to demonstrate its usage here).<\/li>\n<li>Add the <em>description<\/em> field to the <em>TodoDocument<\/em> class and annotate this field with the <em>@Field<\/em> annotation.<\/li>\n<li>Add the <em>title<\/em> field to the <em>TodoDocument<\/em> and annotate this field with the <em>@Field<\/em> annotation.<\/li>\n<li>Create getter methods to the fields of the <em>TodoDocument<\/em> class.<\/li>\n<li>Create a static inner class which is used to build new <em>TodoDocument<\/em> objects.<\/li>\n<li>Add a static <em>getBuilder()<\/em> method to the <em>TodoDocument<\/em> class. The implementation of this method returns a new <em>TodoDocument.Builder<\/em> object.<\/li>\n<\/ol>\n<p>The source code of the <em>TodoDocument<\/em> class looks as follows:<\/p>\n<pre class=\"brush:java\">import org.apache.solr.client.solrj.beans.Field;\r\nimport org.springframework.data.annotation.Id;\r\n\r\npublic class TodoDocument {\r\n\r\n    @Id\r\n    @Field\r\n    private String id;\r\n\r\n    @Field\r\n    private String description;\r\n\r\n    @Field\r\n    private String title;\r\n\r\n    public TodoDocument() {\r\n\r\n    }\r\n\r\n    public static Builder getBuilder(Long id, String title) {\r\n        return new Builder(id, title);\r\n    }\r\n\r\n    \/\/Getters are omitted\r\n\r\n    public static class Builder {\r\n        private TodoDocument build;\r\n\r\n        public Builder(Long id, String title) {\r\n            build = new TodoDocument();\r\n            build.id = id.toString();\r\n            build.title = title;\r\n        }\r\n\r\n        public Builder description(String description) {\r\n            build.description = description;\r\n            return this;\r\n        }\r\n\r\n        public TodoDocument build() {\r\n            return build;\r\n        }\r\n    }\r\n}<\/pre>\n<h2>Creating the Repository Interface<\/h2>\n<p>The base interface of Spring Data Solr repositories is the <em>SolrCrudRepository&lt;T, ID&gt;<\/em> interface and each repository interface must extend this interface.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>When we extend the <em>SolrCrudRepository&lt;T, ID&gt;<\/em> interface, we must give two type parameters which are described in the following:<\/p>\n<ul>\n<li>The <em>T<\/em> type parameter means the type of our document class.<\/li>\n<li>The <em>ID<\/em> type parameter means the type of the document\u2019s id. Spring Data Solr (version 1.0.0.RC1) requires that the id of a document is <em>String<\/em>.<\/li>\n<\/ul>\n<p>We can create the repository interface by following these steps:<\/p>\n<ol>\n<li>Create an interface called <em>TodoDocumentRepository<\/em>.<\/li>\n<li>Extend the <em>SolrCrudRepository<\/em> interface and give the type of our document class and its id as type parameters.<\/li>\n<\/ol>\n<p>The source code of the <em>TodoDocumentRepository<\/em> interface looks as follows:<\/p>\n<pre class=\"brush:java\">import org.springframework.data.solr.repository.SolrCrudRepository;\r\n\r\npublic interface TodoDocumentRepository extends SolrCrudRepository&lt;TodoDocument, String&gt; {\r\n}<\/pre>\n<h2>Creating the Service<\/h2>\n<p>Our next step is to create the service which uses the created Solr repository. We can create this service by following these steps:<\/p>\n<ol>\n<li>Create a service interface.<\/li>\n<li>Implement the created interface.<\/li>\n<\/ol>\n<p>These steps are described with more details in the following.<\/p>\n<h4>Creating the Service Interface<\/h4>\n<p>Our service interface declares two methods which are described in the following:<\/p>\n<ul>\n<li>The <em>void addToIndex(Todo todoEntry)<\/em> method adds a todo entry to the index.<\/li>\n<li>The <em>void deleteFromIndex(Long id)<\/em> method deletes a todo entry from the index.<\/li>\n<\/ul>\n<p><strong>Note:<\/strong> We can use the <em>addToIndex()<\/em> method for adding new todo entries to the Solr index and updating the information of existing todo entries. If an existing document has the same id than the new one, the old document is deleted and the information of the new document is saved to the Solr index (See <a href=\"http:\/\/wiki.apache.org\/solr\/SchemaXml#The_Unique_Key_Field\" target=\"_blank\">SchemaXML @ Solr Wiki<\/a> for more details).<\/p>\n<p>The source code of the <em>TodoIndexService<\/em> interface looks as follows:<\/p>\n<pre class=\"brush:java\">public interface TodoIndexService {\r\n\r\n    public void addToIndex(Todo todoEntry);\r\n\r\n    public void deleteFromIndex(Long id);\r\n}<\/pre>\n<h4>Implementing the Created Interface<\/h4>\n<p>We cam implement the service interface by following these steps:<\/p>\n<ol>\n<li>Create a skeleton implementation of our service class.<\/li>\n<li>Implement the method used to add documents to the Solr index.<\/li>\n<li>Implement the method used to delete documents from the Solr index.<\/li>\n<\/ol>\n<p>These steps are described with more details in the following.<\/p>\n<h2>Creating a Skeleton Implementation of the Service Class<\/h2>\n<p>We can create a skeleton implementation of our service interface by following these steps:<\/p>\n<ol>\n<li>Create a class called <em>RepositoryTodoIndexService<\/em> and annotate this class with the <em>@Service<\/em> annotation. This annotation marks this class as a service and ensures that the class will be detected during the classpath scanning.<\/li>\n<li>Add a <em>TodoDocumentRepository<\/em> field to the <em>RepositoryTodoIndexService<\/em> class and annotate that field with the <em>@Resource<\/em> annotation. This annotation instructs the Spring IoC container to inject the actual repository implementation the service\u2019s <em>repository<\/em> field.<\/li>\n<\/ol>\n<p>The source code of our dummy service implementation looks as follows:<\/p>\n<pre class=\"brush:java\">import org.springframework.stereotype.Service;\r\nimport org.springframework.transaction.annotation.Transactional;\r\n\r\nimport javax.annotation.Resource;\r\n\r\n@Service\r\npublic class RepositoryTodoIndexService implements TodoIndexService {\r\n\r\n    @Resource\r\n    private TodoDocumentRepository repository;\r\n\r\n    \/\/Add methods here\r\n}<\/pre>\n<h2>Adding Documents to the Solr Index<\/h2>\n<p>We can create the method which adds new documents to the Solr index by following these steps:<\/p>\n<ol>\n<li>Add the <em>addToIndex()<\/em> method to the <em>RepositoryTodoIndexService<\/em> class and annotate this method with the <em>@Transactional<\/em> annotation. This ensures that our <a href=\"http:\/\/static.springsource.org\/spring-data\/data-solr\/docs\/1.0.0.RC1\/reference\/htmlsingle\/#solr.transactions\" target=\"_blank\">Spring Data Solr repository will participate in Spring managed transactions<\/a>.<\/li>\n<li>Create a new <em>TodoDocument<\/em> object by using the builder pattern. Set the <em>id<\/em>, <em>title<\/em> and <em>description<\/em> of the created document.<\/li>\n<li>Add the document to the Solr index by calling the <em>save()<\/em> method of the <em>TodoDocumentRepository<\/em> interface.<\/li>\n<\/ol>\n<p>The source code of the created method looks as follows:<\/p>\n<pre class=\"brush:java\">import org.springframework.stereotype.Service;\r\nimport org.springframework.transaction.annotation.Transactional;\r\n\r\nimport javax.annotation.Resource;\r\n\r\n@Service\r\npublic class RepositoryTodoIndexService implements TodoIndexService {\r\n\r\n    @Resource\r\n    private TodoDocumentRepository repository;\r\n\r\n    @Transactional\r\n    @Override\r\n    public void addToIndex(Todo todoEntry) {\r\n        TodoDocument document = TodoDocument.getBuilder(todoEntry.getId(), todoEntry.getTitle())\r\n                .description(todoEntry.getDescription())\r\n                .build();\r\n       \r\n        repository.save(document);\r\n    }\r\n\r\n    \/\/Add deleteFromIndex() method here\r\n}<\/pre>\n<h2>Deleting Documents from the Solr Index<\/h2>\n<p>We can create a method which deletes documents from the Solr index by following these steps:<\/p>\n<ol>\n<li>Add the <em>deleteFromIndex()<\/em> method to the <em>RepositoryTodoDocumentService<\/em> class and annotate this method with the <em>@Transactional<\/em> annotation. This ensures that our <a href=\"http:\/\/static.springsource.org\/spring-data\/data-solr\/docs\/1.0.0.RC1\/reference\/htmlsingle\/#solr.transactions\" target=\"_blank\">Spring Data Solr repository will participate in Spring managed transactions<\/a>.<\/li>\n<li>Delete document from the Solr index by calling the <em>delete()<\/em> method of the <em>TodoDocumentRepository<\/em> interface.<\/li>\n<\/ol>\n<p>The source code of the created method looks as follows:<\/p>\n<pre class=\"brush:java\">import org.springframework.stereotype.Service;\r\nimport org.springframework.transaction.annotation.Transactional;\r\n\r\nimport javax.annotation.Resource;\r\n\r\n@Service\r\npublic class RepositoryTodoIndexService implements TodoIndexService {\r\n\r\n    @Resource\r\n    private TodoDocumentRepository repository;\r\n\r\n    \/\/Add addToIndex() method here\r\n\r\n    @Transactional\r\n    @Override\r\n    public void deleteFromIndex(Long id) {\r\n        repository.delete(id.toString());\r\n    }\r\n}<\/pre>\n<h2>Using the Created Service<\/h2>\n<p>Our last step is to use the service which we created earlier. We can do this by making the following modifications to the <em>RepositoryTodoService<\/em> class:<\/p>\n<ol>\n<li>Add the <em>TodoIndexService<\/em> field to the the <em>RepositoryTodoService<\/em> class and annotate this field with the <em>@Resource<\/em> annotation. This annotation instructs the Spring IoC container to inject the created <em>RepositoryTodoIndexService<\/em> object to the service\u2019s <em>indexService<\/em> field.<\/li>\n<li>Call the <em>addToIndex()<\/em> method of the <em>TodoIndexService<\/em> interface in the <em>add()<\/em> method of the <em>RepositoryTodoService<\/em> class.<\/li>\n<li>Call the <em>deleteFromIndex()<\/em> method of the <em>TodoIndexService<\/em> interface in the <em>deleteById()<\/em> method of the <em>RepositoryTodoService<\/em> class.<\/li>\n<li>Call the <em>addToIndex()<\/em> method of the <em>TodoIndexService<\/em> interface in the update() method of the <em>RepositoryTodoService<\/em> class.<\/li>\n<\/ol>\n<p>The source code of the <em>RepositoryTodoService<\/em> looks as follows:<\/p>\n<pre class=\"brush:java\">import org.springframework.security.access.prepost.PreAuthorize;\r\nimport org.springframework.stereotype.Service;\r\nimport org.springframework.transaction.annotation.Transactional;\r\n\r\nimport javax.annotation.Resource;\r\nimport java.util.List;\r\n\r\n@Service\r\npublic class RepositoryTodoService implements TodoService {\r\n\r\n    @Resource\r\n    private TodoIndexService indexService;\r\n\r\n    @Resource\r\n    private TodoRepository repository;\r\n\r\n    @PreAuthorize(\"hasPermission('Todo', 'add')\")\r\n    @Transactional\r\n    @Override\r\n    public Todo add(TodoDTO added) {\r\n        Todo model = Todo.getBuilder(added.getTitle())\r\n                .description(added.getDescription())\r\n                .build();\r\n\r\n        Todo persisted = repository.save(model);\r\n        indexService.addToIndex(persisted);\r\n\r\n        return persisted;\r\n    }\r\n\r\n    @PreAuthorize(\"hasPermission('Todo', 'delete')\")\r\n    @Transactional(rollbackFor = {TodoNotFoundException.class})\r\n    @Override\r\n    public Todo deleteById(Long id) throws TodoNotFoundException {\r\n        Todo deleted = findById(id);\r\n\r\n        repository.delete(deleted);\r\n        indexService.deleteFromIndex(id);\r\n\r\n        return deleted;\r\n    }\r\n\r\n    @PreAuthorize(\"hasPermission('Todo', 'update')\")\r\n    @Transactional(rollbackFor = {TodoNotFoundException.class})\r\n    @Override\r\n    public Todo update(TodoDTO updated) throws TodoNotFoundException {\r\n        Todo model = findById(updated.getId());\r\n\r\n        model.update(updated.getDescription(), updated.getTitle());\r\n        indexService.addToIndex(model);\r\n\r\n        return model;\r\n    }\r\n}<\/pre>\n<h2>Summary<\/h2>\n<p>We have successfully created an application which adds documents to the Solr index and deletes documents from it. This blog entry has taught us the following things:<\/p>\n<ul>\n<li>We learned how we can create document classes.<\/li>\n<li>We learned that we can create Spring Data Solr repositories by extending the <em>SolrCrudRepository<\/em> interface.<\/li>\n<li>We learned that Spring Data Solr assumes by default that the name of the document\u2019s id field is \u2018id\u2019. However, we can override this setting by annotating the id field with the <a href=\"http:\/\/static.springsource.org\/spring-data\/commons\/docs\/current\/api\/org\/springframework\/data\/annotation\/Id.html\" target=\"_blank\"><em>@Id<\/em><\/a> annotation.<\/li>\n<li>We learned that at the moment Spring Data Solr (version 1.0.0.RC1) expects that the id of a document is <em>String<\/em>.<\/li>\n<li>We learned how we can add documents to the Solr index and delete documents from it.<\/li>\n<li>We learned that Spring Data Solr repositories can participate in Spring managed transactions.<\/li>\n<\/ul>\n<p>The next part of my Spring Data Solr tutorial describes how we can <a href=\"http:\/\/www.petrikainulainen.net\/programming\/solr\/spring-data-solr-tutorial-query-methods\/\">search information from the Solr index by using query methods<\/a>.<\/p>\n<p>P.S. The example application of this blog entry is available at <a href=\"https:\/\/github.com\/pkainulainen\/spring-data-solr-examples\/tree\/master\/query-methods\" target=\"_blank\">Github<\/a>.<br \/>\n&nbsp;<\/p>\n<div style=\"border: 1px solid #D8D8D8; background: #FAFAFA; width: 100%; padding-left: 5px;\"><b><i>Reference: <\/i><\/b><a href=\"http:\/\/www.petrikainulainen.net\/programming\/solr\/spring-data-solr-tutorial-crud-almost\/\">Spring Data Solr Tutorial: CRUD (Almost)<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Petri Kainulainen at the <a href=\"http:\/\/www.petrikainulainen.net\/\">Petri Kainulainen<\/a> blog.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In the previous part of my Spring Data Solr tutorial, we learned how we can configure Spring Data Solr. Now it is time to take a step forward and learn how we can manage the information stored in our Solr instance. This blog entry describes how we add new documents to the Solr index, update &hellip;<\/p>\n","protected":false},"author":429,"featured_media":80,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[470,30,321],"class_list":["post-12996","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-apache-solr","tag-spring","tag-spring-data"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Spring Data Solr Tutorial: CRUD (Almost)<\/title>\n<meta name=\"description\" content=\"In the previous part of my Spring Data Solr tutorial, we learned how we can configure Spring Data Solr. Now it is time to take a step forward and learn\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2013\/05\/spring-data-solr-tutorial-crud-almost.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Data Solr Tutorial: CRUD (Almost)\" \/>\n<meta property=\"og:description\" content=\"In the previous part of my Spring Data Solr tutorial, we learned how we can configure Spring Data Solr. Now it is time to take a step forward and learn\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2013\/05\/spring-data-solr-tutorial-crud-almost.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2013-05-23T13:00:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-solr-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Petri Kainulainen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/petrikainulaine\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Petri Kainulainen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/spring-data-solr-tutorial-crud-almost.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/spring-data-solr-tutorial-crud-almost.html\"},\"author\":{\"name\":\"Petri Kainulainen\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/5af4df3fdfeb79e9fa3598d79bff2c9e\"},\"headline\":\"Spring Data Solr Tutorial: CRUD (Almost)\",\"datePublished\":\"2013-05-23T13:00:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/spring-data-solr-tutorial-crud-almost.html\"},\"wordCount\":1445,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/spring-data-solr-tutorial-crud-almost.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/apache-solr-logo.jpg\",\"keywords\":[\"Apache Solr\",\"Spring\",\"Spring Data\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/spring-data-solr-tutorial-crud-almost.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/spring-data-solr-tutorial-crud-almost.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/spring-data-solr-tutorial-crud-almost.html\",\"name\":\"Spring Data Solr Tutorial: CRUD (Almost)\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/spring-data-solr-tutorial-crud-almost.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/spring-data-solr-tutorial-crud-almost.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/apache-solr-logo.jpg\",\"datePublished\":\"2013-05-23T13:00:34+00:00\",\"description\":\"In the previous part of my Spring Data Solr tutorial, we learned how we can configure Spring Data Solr. Now it is time to take a step forward and learn\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/spring-data-solr-tutorial-crud-almost.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/spring-data-solr-tutorial-crud-almost.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/spring-data-solr-tutorial-crud-almost.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/apache-solr-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/apache-solr-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/spring-data-solr-tutorial-crud-almost.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Spring Data Solr Tutorial: CRUD (Almost)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/5af4df3fdfeb79e9fa3598d79bff2c9e\",\"name\":\"Petri Kainulainen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9e57425180f323fa65bc519a64c8273d3fcb7c6bd272e56b37dd15613f403659?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9e57425180f323fa65bc519a64c8273d3fcb7c6bd272e56b37dd15613f403659?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9e57425180f323fa65bc519a64c8273d3fcb7c6bd272e56b37dd15613f403659?s=96&d=mm&r=g\",\"caption\":\"Petri Kainulainen\"},\"description\":\"Petri is passionate about software development and continuous improvement. He is specialized in software development with the Spring Framework and is the author of Spring Data book.\",\"sameAs\":[\"http:\\\/\\\/www.petrikainulainen.net\\\/\",\"http:\\\/\\\/www.linkedin.com\\\/in\\\/petrikainulainen\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/petrikainulaine\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/petri-kainulainen\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring Data Solr Tutorial: CRUD (Almost)","description":"In the previous part of my Spring Data Solr tutorial, we learned how we can configure Spring Data Solr. Now it is time to take a step forward and learn","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2013\/05\/spring-data-solr-tutorial-crud-almost.html","og_locale":"en_US","og_type":"article","og_title":"Spring Data Solr Tutorial: CRUD (Almost)","og_description":"In the previous part of my Spring Data Solr tutorial, we learned how we can configure Spring Data Solr. Now it is time to take a step forward and learn","og_url":"https:\/\/www.javacodegeeks.com\/2013\/05\/spring-data-solr-tutorial-crud-almost.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2013-05-23T13:00:34+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-solr-logo.jpg","type":"image\/jpeg"}],"author":"Petri Kainulainen","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/petrikainulaine","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Petri Kainulainen","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/spring-data-solr-tutorial-crud-almost.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/spring-data-solr-tutorial-crud-almost.html"},"author":{"name":"Petri Kainulainen","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/5af4df3fdfeb79e9fa3598d79bff2c9e"},"headline":"Spring Data Solr Tutorial: CRUD (Almost)","datePublished":"2013-05-23T13:00:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/spring-data-solr-tutorial-crud-almost.html"},"wordCount":1445,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/spring-data-solr-tutorial-crud-almost.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-solr-logo.jpg","keywords":["Apache Solr","Spring","Spring Data"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2013\/05\/spring-data-solr-tutorial-crud-almost.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/spring-data-solr-tutorial-crud-almost.html","url":"https:\/\/www.javacodegeeks.com\/2013\/05\/spring-data-solr-tutorial-crud-almost.html","name":"Spring Data Solr Tutorial: CRUD (Almost)","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/spring-data-solr-tutorial-crud-almost.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/spring-data-solr-tutorial-crud-almost.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-solr-logo.jpg","datePublished":"2013-05-23T13:00:34+00:00","description":"In the previous part of my Spring Data Solr tutorial, we learned how we can configure Spring Data Solr. Now it is time to take a step forward and learn","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/spring-data-solr-tutorial-crud-almost.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2013\/05\/spring-data-solr-tutorial-crud-almost.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/spring-data-solr-tutorial-crud-almost.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-solr-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-solr-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/spring-data-solr-tutorial-crud-almost.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Spring Data Solr Tutorial: CRUD (Almost)"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/5af4df3fdfeb79e9fa3598d79bff2c9e","name":"Petri Kainulainen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9e57425180f323fa65bc519a64c8273d3fcb7c6bd272e56b37dd15613f403659?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9e57425180f323fa65bc519a64c8273d3fcb7c6bd272e56b37dd15613f403659?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9e57425180f323fa65bc519a64c8273d3fcb7c6bd272e56b37dd15613f403659?s=96&d=mm&r=g","caption":"Petri Kainulainen"},"description":"Petri is passionate about software development and continuous improvement. He is specialized in software development with the Spring Framework and is the author of Spring Data book.","sameAs":["http:\/\/www.petrikainulainen.net\/","http:\/\/www.linkedin.com\/in\/petrikainulainen","https:\/\/x.com\/https:\/\/twitter.com\/petrikainulaine"],"url":"https:\/\/www.javacodegeeks.com\/author\/petri-kainulainen"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/12996","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/429"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=12996"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/12996\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/80"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=12996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=12996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=12996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}