Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Connect With the Java Thin Client

Survey the GridGain 9 Java thin client: connect with partition awareness, define schema from annotations, navigate the Table package, and access data through RecordView, KeyValueView, and SQL.

Introduction

You have a running cluster and a loaded dataset. In the first tutorial, you built the infrastructure with Docker and created 11 tables with SQL DDL. In the second, you explored the data through the SQL CLI. Now you connect a Java application and survey the API surface that the thin client provides.

The GridGain 9 Java thin client exposes four API surfaces through a single connection:

  • SQL runs queries against tables in the cluster.

  • Tables provides typed object operations over rows.

  • Catalog manages schema from Java annotations.

  • Transactions coordinates ACID operations across tables.

You start with the connection and work through four actions:

  • Define a table schema from an annotated Java class.

  • Navigate the Table package to reach different views of the same data.

  • Read the same row through each view to see what the variants offer.

  • Close with a SQL query that joins your new table with the existing Music Store catalog.

Prerequisites

Returning to these tutorials? Verify your environment.

Check that the cluster is running and the Music Store data is loaded:

Expected result: 3503. If the query succeeds, your environment is ready.

If the containers are stopped, restart them from the directory containing your docker-compose.yml:

Data persists across restarts. Wait 15-30 seconds for the nodes to rejoin, then re-run the check above.

If the cluster was destroyed (docker compose down), start the containers and re-initialize:

Wait 10 seconds for the nodes to start, then load the license and initialize the cluster:

Download the schema and data files:

Copy the files into the container and load them:

The schema loader prints "Updated 0 rows" for each DDL statement. The data loader prints row counts per batch. Both commands emit jline reflection warnings that are cosmetic and safe to ignore.

Re-run the check above to verify 3503 tracks are loaded.

What You Will Learn

  • How the thin client connects with partition awareness

  • The four API surfaces: SQL, Tables, Catalog, and Transactions

  • How annotations define distributed table schema (schema-as-code)

  • How to navigate the Table package from client to view

  • How RecordView, KeyValueView, and SQL access the same data differently

What You Will Build

A Java application that connects to your 3-node cluster, creates a table from an annotated Java class, writes and reads data through RecordView, previews KeyValueView access to the same rows, and queries the data with SQL.

Step 1: Create the Project

Create a directory for the project and add a pom.xml with the GridGain thin client dependency:

The group ID is org.gridgain, but the artifact name keeps the ignite- prefix. All Java packages remain org.apache.ignite.*.

GridGain 9 artifacts are hosted on the GridGain Nexus repository, not Maven Central. The <repositories> block in the pom.xml above is required. Without it, Maven will fail with Could not find artifact org.gridgain:ignite-client.

The ignite-client dependency is the only one you need. It pulls in ignite-api (which contains the annotation classes and table interfaces) as a transitive dependency.

Create the source directory and an empty main class:

Verify the project compiles:

Step 2: Connect and Survey the Client

Replace the contents of MusicStoreClient.java with the connection code:

Key details in this code:

  • try-with-resources creates the client and closes it when the block exits. The inner try around execute() closes the ResultSet, which releases server-side cursor resources.

  • IgniteClient.builder().addresses(...) accepts multiple node addresses. The client opens a connection to every address you configure (host names are re-resolved periodically), so list all node addresses. This is partition awareness: each operation routes directly to the node that owns the data, as long as that node is among the configured addresses. If a node fails, the client reconnects to the remaining nodes.

  • client.sql().execute((Transaction) null, ...) runs a SQL query. The explicit (Transaction) cast ensures the code compiles across all GridGain 9 versions. The null value means the query runs in its own implicit transaction. This is the same SQL API you used through the CLI in the previous tutorial.

System.exit(0) after the try block forces the JVM to shut down immediately. Without it, the GridGain client's background timer thread keeps the process alive for 15 seconds after the connection closes.

Run the application:

The -q flag suppresses Maven's build output so you see only the application's System.out lines.

Step 3: Define a Table Schema With Annotations

In the first tutorial, you created tables with CREATE TABLE statements. The Catalog API offers an alternative: define the schema as an annotated Java class and deploy it with client.catalog().createTable(). This is schema-as-code.

Replace the contents of MusicStoreClient.java:

The @Table annotation transforms a Java class into a distributed table definition. Three annotations define the schema:

  • @Table("Favorite") names the table in the cluster catalog. Without a @Zone annotation, the table lands in the Default zone with a single replica. For development, this is fine. The Music Store tables you created in the first tutorial use an explicit MusicStore zone with 2 replicas, which is a reasonable starting point for production.

  • @Id marks the primary key. In a distributed system, the primary key determines partition routing: the cluster hashes this value to decide which node owns each row. When you look up favoriteId=2, the client routes directly to the node that owns that partition.

  • @Column maps a Java field to a table column. The SQL type is inferred from the Java type: Integer becomes INT, String becomes VARCHAR. The optional length parameter constrains the string size.

Three more annotations are available for production use:

  • @Zone assigns the table to a specific distribution zone (replication factor, partition count, storage profile).

  • @Index defines secondary indexes for query performance.

  • @ColumnRef references columns in colocation and index definitions.

You saw the effect of colocation on join performance in the previous tutorial's EXPLAIN plans.

DROP TABLE IF EXISTS before createTable() keeps the application re-runnable. catalog().dropTable() has no "if exists" guard, so the SQL API handles the idempotent cleanup instead.

Run the application:

The annotated class produced the same result as a CREATE TABLE statement. The table is now in the cluster catalog alongside the 11 Music Store tables, queryable through SQL and accessible through the Table API.

Step 4: The Table Package

The Favorite table is in the catalog. Every interaction with table data follows a three-level path:

  1. client.tables() returns the IgniteTables interface, the entry point for all table operations.

  2. .table("Favorite") returns a Table object representing the physical table in the cluster.

  3. From the Table object, you choose a view that determines how you interact with the data.

A single Table offers four primary view types, organized into two families:

View
Method
Description

RecordView<Favorite>

.recordView(Favorite.class)

Each row is a complete typed POJO

RecordView<Tuple>

.recordView()

Each row is a dynamic Tuple (no POJO needed)

KeyValueView<K, V>

.keyValueView(K.class, V.class)

Each row split into typed key and value objects

KeyValueView<Tuple, Tuple>

.keyValueView()

Each row split into key and value Tuples

RecordView treats each row as a single object. KeyValueView splits each row into a separate key (the @Id columns) and value (everything else). Both families offer typed (POJO) and untyped (Tuple) variants. All four views read and write the same underlying data. The next tutorial covers the full RecordView and KeyValueView operation set.

Add the following code after the System.out.println("Catalog entry: ..." line, before the closing } of the try block:

upsertAll() writes all three records in a single call. The operation is idempotent: running the application twice overwrites existing rows instead of failing on duplicate keys. The first parameter is the transaction context: null means each operation runs in its own implicit transaction.

get() performs a key-based lookup. The client uses the @Id field to compute the partition hash and routes the request directly to the node that owns that partition. Only the key field needs a value in the lookup object; the cluster fills in the remaining columns from storage and returns the complete record.

The three TrackIds (1613, 2254, 1990) reference real rows in the Music Store's Track table. Step 5 resolves these IDs to track names with a SQL JOIN.

Run the application:

Step 5: Access the Same Data Through KeyValueView and SQL

The three favorites you wrote through RecordView are visible to every other view of the same table. This step reads the same data through an untyped KeyValueView lookup and a SQL JOIN that crosses zone boundaries.

Add the following code after the System.out.println("RecordView lookup: ..." line, before the closing } of the try block:

Three access patterns, one table:

  • KeyValueView splits each row into a key (the @Id columns) and a value (everything else). The keyValueView() call here returns the untyped KeyValueView<Tuple, Tuple>. A typed variant, keyValueView(Key.class, Value.class), maps to POJOs instead. The next tutorial covers both.

  • Tuple is GridGain's dynamic column container. Write with .set("favoriteId", 2). Read with typed accessors: .intValue("trackId"), .stringValue("note"). No POJO class required.

  • SQL JOIN confirms that data written through RecordView appears immediately in SQL queries. It also confirms that tables in different zones (Favorite in Default, Track in MusicStore) join without additional configuration.

Run the application:

The same favoriteId=2 record appears three times across three access patterns: as a Favorite POJO from RecordView, as a key-value Tuple pair from KeyValueView, and as a joined SQL row with the track name resolved. One schema, multiple views.

Step 6: Clean Up

In Step 3, you used client.catalog().createTable() to deploy a schema. The Catalog API also handles the reverse: dropTable() removes a table from the cluster. Drop the Favorite table so future tutorials start with a clean 11-table schema.

Add the following code after the while loop that prints the favorites, before the closing } of the try block:

The Catalog API also includes methods not used in this tutorial:

  • createZone(ZoneDefinition) and dropZone(String) manage distribution zones programmatically, the same zones you created with CREATE ZONE in the first tutorial.

  • tableDefinition(String) and zoneDefinition(String) inspect existing schema definitions.

Every Catalog and Table API method has an async variant that returns CompletableFuture for non-blocking workflows.

Run the complete application one final time:

The Favorite table is gone and all 11 Music Store tables remain intact.

Summary

You connected a Java application to the GridGain 9 cluster and exercised the thin client's four API surfaces. Here is a map of every API call you made, organized by the surface it belongs to.

DDL, DML, and Where SQL Fits

The thin client separates schema management from data operations:

  • client.catalog() is the DDL surface. It manages tables and zones from Java code.

  • client.tables() is the DML surface. It reads and writes data through typed views.

  • client.sql() crosses both. CREATE TABLE is DDL through SQL. SELECT is DML through SQL.

  • client.transactions() coordinates ACID transactions across multiple operations.

Operation
Surface
Step

catalog().createTable(Favorite.class)

DDL via Catalog API

Step 3

catalog().dropTable("Favorite")

DDL via Catalog API

Step 6

sql().execute("DROP TABLE IF EXISTS ...")

DDL via SQL API

Step 3

sql().execute("SELECT COUNT(*) ...")

DML via SQL API

Steps 2, 5, 6

favorites.upsertAll(...)

DML via Table API (RecordView)

Step 4

favorites.get(...)

DML via Table API (RecordView)

Step 4

kvView.get(...)

DML via Table API (KeyValueView)

Step 5

Schema-as-code

Annotations define the schema in Java:

  • @Table names the table that the Catalog API creates.

  • @Id marks the primary key, which determines partition routing.

  • @Column maps each field to a column in the table.

client.catalog().createTable(Favorite.class) deploys the schema. The result is identical to the CREATE TABLE statements you wrote in the first tutorial. Additional annotations (@Zone, @Index, @ColumnRef) handle distribution zones, secondary indexes, and colocation.

The Table Package Hierarchy

Every data interaction follows the same three-level path: client.tables() returns IgniteTables, .table("Favorite") returns the physical Table, and from there you choose a view. A single Table offers four primary view types across two families: RecordView (each row is one object) and KeyValueView (each row split into key and value). Both families offer typed (POJO) and untyped (Tuple) variants.

One Table, Multiple Access Patterns

You accessed the same favoriteId=2 record three ways: as a Favorite POJO through RecordView, as a key-value Tuple pair through KeyValueView, and as a joined SQL row with the track name resolved. All views read and write the same underlying data. Choose RecordView for type-safe business logic, KeyValueView for key-oriented access patterns, and SQL for queries that are easier to express relationally (joins, aggregations, filtering across tables).

Next Step

Continue to Work with RecordView and KeyValueView to work with the Music Store dataset: insert, replace, delete, bulk operations, and the criteria for choosing between views.

This page is: Copyright © 2026 MariaDB. All rights reserved.

Last updated

Was this helpful?