Using jetstreamDB as in-memory Database for Java

June 30th, 2018 by

JetstreamDB is a in-memory database engine for Java that claims to be built for ultra-high speed and the ability of managing complex data structures by storing real Java objects instead of serializing data structures to other database specific formats.

In the following short example I would like to demonstrate how to create and read items from such a database by building a small article management sample app.

Using jetstreamDB for Java

Using jetstreamDB for Java


Project Setup

First of all we’re adding some Maven repositories to our project’s pom.xml:


Afterwards just need to add the following dependency:


Sample Application

We’re now implementing a sample application to store and retreive some data from a jetstreamDB…

Root Entity

This is our aggregate, the root of our persisted data:

package com.hascode.tutorial;
import java.util.ArrayList;
import java.util.List;
public class RootData {
  private final List<Article> articles = new ArrayList<>();
  public List<Article> getArticles() {
    return articles;

Article Entity

This is our article entity

package com.hascode.tutorial;
public class Article {
  private final String title;
  // constructor, getter, setter, tostring ommitted..

Command Line App

This is our command line app that allows us to create and list our articles:

package com.hascode.tutorial;
import com.jetstreamdb.JetstreamDBInstance;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
public class ArticleApp {
  private static final String USAGE = "Enter a command 'l': list, 'a': add, 'q': quit 'd': db info\n";
  private JetstreamDBInstance<RootData> db;
  public ArticleApp() {
    db = JetstreamDBInstance.New("my-articles-db ", RootData.class);
    Path databaseDirectory = Paths.get("").resolve("article-db");
    System.out.printf("creating database directory in %s%n", databaseDirectory.toAbsolutePath());
  public static void main(String[] args) {
    new ArticleApp().run();
  public void run() {
  private void prompt() {
    Console console = System.console();
    String command = console.readLine();
    switch (command) {
      case "q":
      case "l":
        List<Article> articles = db.root().getArticles();
        System.out.printf("%d articles found:%n", articles.size());
      case "a":
        System.out.println("Please enter a title");
        String title = console.readLine();
        List<Article> update = db.root().getArticles();
        update.add(new Article(title));;
      case "d":
        System.out.printf("basedir: %s, name: %s%n", db.configuration().getBaseDir(),
        System.out.println("invalid command");

Running the Application

Now we’d like to add and fetch some data from our application:

We may start the application using our IDE or using Maven in the command line like this:

mvn clean compile exec:java -Dexec.mainClass=com.hascode.tutorial.ArticleApp
            y+  .oy/.        `:oy/
            ho /h:              `sy`
           smmmoy+               d/dmmd/          JetstreamDB
          -mmmm+h/               h/dmmmh
          -mmmmh/y+`           .oy+mmmmd          Version 1.0.0-beta1
          :mh+- -yo. .:++o+/:``:so``/sdd
         :h/      .+so+//:/+oss/`     .oy.
        :d.   ``      `.:m-.`      ``   /d.
        h+    oo        .d`        +s    so
        d:    oo        .d` /oooo- +s    +y
        h/    oo        .d`        +s    +y
        /h----yo        `:         +y----h+
         sd/::yo                   +y::/ds
          :yo:so                   +s:oy/
            ./ho        .d`        oh/.
              so        .d`        +y
              oo        .d`        +y
creating database directory in /data/project/jetstream-tutorial/article-db
Enter a command 'l': list, 'a': add, 'q': quit 'd': db info
0 articles found:
Enter a command 'l': list, 'a': add, 'q': quit 'd': db info
Please enter a title
Some title
Enter a command 'l': list, 'a': add, 'q': quit 'd': db info
1 articles found:
Article{title='Some title'}
Enter a command 'l': list, 'a': add, 'q': quit 'd': db info
basedir: article-db, name: my-articles-db
Enter a command 'l': list, 'a': add, 'q': quit 'd': db info
Please enter a title
another one
Enter a command 'l': list, 'a': add, 'q': quit 'd': db info
2 articles found:
Article{title='Some title'}
Article{title='another one'}
Enter a command 'l': list, 'a': add, 'q': quit 'd': db info

Internal Structure

Having created those articles we can see that jetstreamDB has created the following files in the designated directory:

├── channel_0
│   ├── channel_0_1.dat
│   └── transactions_0.sft
├── ObjectId.oid
├── PersistenceTypeDictionary.ptd
└── TypeId.tid

Tutorial Sources

Please feel free to download the tutorial sources from my Bitbucket repository, fork it there or clone it using Git:

git clone


Tags: , , ,

11 Responses to “Using jetstreamDB as in-memory Database for Java”

  1. Anonymous Says:

    Which Java version did you use. I tried with Java 10 – fresh clone from bitbucket – and it just crashed

  2. Micha Kops Says:

    I’ve used Java 8 (

    Which error did you encounter with Java 10? Some Illegal reflective access error?

  3. Marcel Says:

    No a class cast exception, I will try again with Java 8. Below my stack trace

    java.lang.ClassCastException: [B cannot be cast to [C

    at com.jetstreamdb.memory.Memory.accessChars(
    at com.jetstreamdb.persistence.binary.types.BinaryPersistence.storeStringsAsList(
    at com.jetstreamdb.persistence.binary.types.BinaryPersistence.storeStringsAsList(
    at com.jetstreamdb.persistence.binary.types.BinaryStorer$Implementation.storeItem(
    at com.jetstreamdb.persistence.binary.types.BinaryStorer$Implementation.storeGraph(
    at com.jetstreamdb.persistence.binary.types.BinaryStorer$
    at com.jetstreamdb.persistence.types.PersistenceManager$
    at com.jetstreamdb.JetstreamDBInstance.createAndStartStorageManager(
    at com.jetstreamdb.JetstreamDBInstance.start(
    at com.jetstreamdb.JetstreamDBInstance.root(
    at net.tangly.erp.crm.db.CrmRoot.addFoo(
    at net.tangly.erp.crm.db.CrmRootTest.testCrmRoot(

  4. Marcel Says:

    Java 8 works fine. It seems that the library is not compatible with Java 10 or Java 11. Thanks for the hint.

  5. Micha Kops Says:

    You’re welcome! Thanks for keeping me up-to-date :)

  6. ChrisPac Says:

    With using Java8, I get the following exception when starting the unchanged example:

    Exception in thread “main” java.lang.NoClassDefFoundError: com/jetstreamdb/collections/types/XGettingCollection
    at com.hascode.tutorial.ArticleApp.(
    at com.hascode.tutorial.ArticleApp.main(
    Caused by: java.lang.ClassNotFoundException: com.jetstreamdb.collections.types.XGettingCollection
    at Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    … 2 more

  7. ChrisPac Says:

    Oh, it was just a corrupt JAR file. Just removed it from local repository and updated maven – everything fine!

  8. Micha Kops Says:

    Hi, I’m glad that it’s working for you now, thanks for the update! :)

  9. nik Says:

    Which license has jetstreamdb?

  10. ds Says:


    I also have the same error “An illegal reflective access operation has occurred” on Java 9+.
    I’m currently evaluating your library but we are switching to Java 11.
    So could you let me know if you intend to make the library compatible for Java 9+ or do you have a hint how I make a workaround.


  11. Micha Kops Says:

    it’s not my library, I have only written an article about it. Please consider contacting the vendor for such questions:

    Best regards

Leave a Reply

Please note, that no personal information like your IP address is stored and you're not required to enter you real name.

Comments must be approved before they are published, so please be patient after having posted a comment - it might take a short while.

Please leave these two fields as-is: