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
A running 3-node cluster with the Music Store dataset from Start Your Local GridGain 9 Development Cluster
Java 17 or later
Maven 3.8 or later
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.*.
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-resourcescreates the client and closes it when the block exits. The innertryaroundexecute()closes theResultSet, 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. Thenullvalue 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@Zoneannotation, the table lands in theDefaultzone with a single replica. For development, this is fine. The Music Store tables you created in the first tutorial use an explicitMusicStorezone with 2 replicas, which is a reasonable starting point for production.@Idmarks 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.@Columnmaps a Java field to a table column. The SQL type is inferred from the Java type:IntegerbecomesINT,StringbecomesVARCHAR. The optionallengthparameter constrains the string size.
Three more annotations are available for production use:
@Zoneassigns the table to a specific distribution zone (replication factor, partition count, storage profile).@Indexdefines secondary indexes for query performance.@ColumnRefreferences 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:
client.tables()returns theIgniteTablesinterface, the entry point for all table operations..table("Favorite")returns aTableobject representing the physical table in the cluster.From the
Tableobject, you choose a view that determines how you interact with the data.
A single Table offers four primary view types, organized into two families:
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
@Idcolumns) and a value (everything else). ThekeyValueView()call here returns the untypedKeyValueView<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)anddropZone(String)manage distribution zones programmatically, the same zones you created withCREATE ZONEin the first tutorial.tableDefinition(String)andzoneDefinition(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 TABLEis DDL through SQL.SELECTis DML through SQL.client.transactions()coordinates ACID transactions across multiple operations.
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:
@Tablenames the table that the Catalog API creates.@Idmarks the primary key, which determines partition routing.@Columnmaps 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.
Related
Start Your Local GridGain 9 Development Cluster for the cluster setup and dataset this tutorial connects to
Create Tables and Query Data with SQL for the SQL patterns you saw through the CLI
How to Configure Logging for the Java Thin Client for controlling log output in your application
This page is: Copyright © 2026 MariaDB. All rights reserved.
Last updated
Was this helpful?

