We are delighted to announce that the eagerly awaited Spring Data Couchbase 4.0 is now available with enhanced capabilities. Built on top of Couchbase Java SDK 3.0, Spring Data Couchbase out-of-the-box comes with technology enhancements and leverages the latest Couchbase Server 6.5 capabilities. These improvements are targeted to maximize developer agility, offer reduced code impedance, enhance manageability, and provide quality developer experience.

Reference Links

Introduction

If you are already familiar with Spring Data and want to overcome the curiosity you may do so now by going to the updates section.

Before getting into what’s changed in Spring Data Couchbase, let’s take a moment to step back and understand what Spring Data is, what  problems it solves and why a developer should consider using it. 

Most developers are familiar with a database, the de-facto standard for data persistence. Today, almost all applications rely on some type of technology that is responsible for persistent storage with more modern enterprise applications commonly adopting the use of a multi-model database.

Regardless of the technology used as a persistence store, operations performed on data have largely remained consistent. The consistency in operations comes from developers, over a period of time, writing thousands of lines of code over and over again to Create, Retrieve, Update and Delete data from their underlying persistence store. As a developer you always want to avoid writing such repetitive and monotonous code, rather you want to focus on writing business logic that brings in more value.

Over a decade, repository patterns have gained a lot of popularity and traction in the developer community. In its modern interpretation, a repository pattern abstracts the data store and enables your business logic to define, read and write operations on a logical level. These patterns are good from an abstractions point of view however it still doesn’t solve the core problem of a developer writing repetitive code. Implementing repository patterns and writing your own data access could leave you with a lot of spaghetti code making maintainability a nightmare, and could also be violating the D.R.Y principle. This is where Spring Data comes to our rescue.

Spring Data is a high-level Pivotal project whose purpose is to unify and ease the access to different kinds of persistence stores, both relational database systems and NoSQL data stores. Spring Data provides generic interfaces for these aspects (CrudRepository, PagingAndSortingRepository) as well as persistence store specific implementations.

With Spring Data’s repositories, you need only to write an interface with finder methods defined according to a given set of conventions (which may vary depending on the kind of persistence store you are using). Spring Data will provide an appropriate implementation of that interface at runtime.

Spring Data for Couchbase, on the other hand,  is part of the umbrella Spring Data project that is maintained and fully supported by Couchbase to Enterprise subscribers. Spring Data for Couchbase aims to provide a familiar and consistent programming model for new data-stores while retaining store-specific features and capabilities. With Spring Data Couchbase you get the simplicity of Spring Data combined with the power of Couchbase!.

What’s changed in Spring Data Couchbase 4.0

Spring Data Couchbase 4.0 is built on top of Couchbase Java SDK 3.0.

Couchbase Java SDK 3.0 is a complete rethink of the 2.x API, providing a simpler surface area and adding support for future Couchbase Server features like Collections, Scopes and transactions (available since Couchbase Server 6.5 as a developer preview). 

Couchbase Server Version Support

To stay in accordance with the feature support, the minimum Couchbase Server version requirement has been bumped up to 5.5 and later. 

N1QL for Querying

Going forward N1QL will be the primary implementation when it comes to working with custom repository methods as well as the built in ones.  Because Spring Data pre-dated N1QL, it used older services by default. If you have used N1QL with Spring Data in the past, don’t worry, there are no significant behavioral changes when implementing N1QL queries with Spring Data Couchbase 4.0.

Automatic Index Management

Although the concept of Automatic Index Management is not new, index management has been enhanced and is more N1QL centric. While some of the Index annotations like ViewIndexes are removed as they stand no more relevance, many new Index annotations are added to the annotations family that will provide enriched capabilities like field level indexing, composite field indexes and more.

Entities

Nothing has changed when it comes to dealing with entities, however switching between imports has become easier than ever. Any annotations that were a part of Couchbase SDK 2.x have now been dropped, which also means that developers get to stick to default spring data annotations.

Templates

ReactiveCouchbaseTemplate and CouchbaseTemplate have been overhauled in general, moving to a Fluent API instead of method overloads. In addition we moved from RxJava to Reactor for the reactive template which, in turn, provides seamless integration into the spring ecosystem.Template method names have been generalized for ease of use, and any view based methods have been removed. Also, new methods that leverage Couchbase analytics service and replicas have been introduced.

Transactions

Developers can now natively use all transaction features that are available to them through Couchbase SDK 3.0. This way developers can have full programmatic control over transactions.

Configuration

Previous versions of Spring-Data allowed configurations via both XML and Java-based annotations however, with this release XML based configuration has been removed.  

Views

Views existed prior to N1QL came into existence. Spring-Data 3.x emphasized use of View over N1QL for some aspects of the repositories which were then still evolving. Over the past few years there has been drastic advancement in N1QL with respect to performance, scalability and integration with search capabilities, in order to maximize the benefit out of N1QL, starting in Spring Data 4.0 support for Views has been removed.

So What’s Next ?

We would love to hear from you on how you liked the 4.0 features and how they will benefit your business going forward. You can also try some of the examples found here. Please don’t forget to share your feedback via the comments or in the forum.

Posted by Arun Vijayraghavan

Arun Vijayraghavan is a Principal Product Manager for SDK at Couchbase. Arun's career spans over 20 years as a Technology practitioner. Arun holds dual master degree's in Physics and Information Technology from University of Madras, India.

3 Comments

  1. HohenheimsenbergMay 12, 2020 at 4:17 pm

    Using these imports I get a jdb error

    implementation ‘org.springframework.boot:spring-boot-starter-actuator’
    implementation ‘org.springframework.boot:spring-boot-starter-webflux’
    implementation ‘org.springframework.data:spring-data-couchbase:4.0.0.RELEASE’
    implementation ‘org.modelmapper.extensions:modelmapper-spring:2.3.0’
    implementation ‘org.springframework.boot:spring-boot-starter-log4j2’

    Caused by: java.lang.ClassNotFoundException: org.springframework.jdbc.CannotGetJdbcConnectionException

    1. Thanks for reaching out, can you please give more details in this forum

      https://forums.couchbase.com/c/java-sdk

      There were be many developers who can help you out there.

      This could be a missing maven reference.

    2. You cannot use boot right now with spring data 4 – you need to wait until boot 2.3 is released (very soon) which has it as a dependency with autoconfigure and everything. You can use older boot versions, but then you need to make sure that no autoconfigure or anything else is on the classpath.

      Also note that couchbase doesn’t do anything with JDBC, so I’m not sure how this is related to Couchbase

Leave a reply