This is the first part of an introductory series on using JHipster with Cassandra: it is aimed at people getting started with using both tools together, but some basic Cassandra and Spring Boot knowledge is expected to understand it fully.
It is written by Julien Dubois, the JHipster lead, who also coded the Cassandra support in JHipster.
This series is in 3 parts:
Today we start with the first part, how Cassandra support works with JHipster.
JHipster is an application generator that focuses on Spring Boot and AngularJS. It is a very popular Open Source project hosted on GitHub, and you can find a lot of information on its website at http://jhipster.github.io/.
JHipster supports what Martin Fowler calls Polyglot Persistence: by default is uses a classical SQL datastore (using JPA/Hibernate), but it also support as an option MongoDB and Cassandra. The AngularJS front-end and most of the Java (Spring-based) code will work identically, but of course the data access layer is specific to the underlying datastore.
During application generation, JHipster allows to select Cassandra as a persistent datastore. This will generate:
The Spring Boot configuration allows to configure the DataStax CQL driver using a Spring Boot YAML file. By default, this file is located in your *src/main/resources/config/application.yml *configuration file:
For SQL and MongoDB datastores, JHipster uses the Spring Data project (namely Spring Data JPA and Spring Data MongoDB), which allows for very concise and efficient code. Unfortunately, Spring Data Cassandra does not have the same level of support (at the time of this writing), so the data access layer is coded directly using the DataStax CQL driver. At Ippon Technologies, we have already used this approach successfully for several clients, and for us this has proven to be the best choice when using Cassandra with Spring Boot.
Here is a UserRepository generated by JHipster, and an example “Foo” entity generated with the JHipster entity sub-generator.
All repositories (for example the UserRepository) follow the same model:
We generally advice people not use Cassandra’s indexes (see “when not to use an index” from the official documentation), and we have had many issues with indexes when working on clients projects at Ippon Technologies.
On the other hand, managing indexes manually, in a specific “index table”, has always been successful for us:
For JHipster, we have used this principle to handle indexes for the “User” table, so a user can be looked up by e-mail, login, or activation key. Here is the CQL script for the “User” table and its “index tables”.
Those three keys have a very high cardinality: if you looked at the section “when not to use an index” in the official documentation, you know those should not be indexed by Cassandra. That’s why we created separate index tables for those keys, and that we manage them manually in the repository.
This design can of course be criticized:
Following this first article on using Cassandra with JHipster, we will post tomorrow another blog post discussing how to model that data with Cassandra, and how it is stored internally in the database.