Free tools Windows power users keep installed
One-click scans. No signup required.
To store different Java engine types in a NoSQL database, persist an explicit type discriminator alongside each engine’s data, map that discriminator to concrete Java classes, and use a persistence converter to bridge the Java object and the database representation. A Jakarta NoSQL example applies this pattern to a Machine document whose engine can be either gas or electric.
What polymorphism means in this example
Here, polymorphism is about mapping Java subtype instances to and from stored JSON. Application code can refer to an abstract Engine type while individual documents retain the information needed to identify a concrete subtype. The pattern is not a claim that document databases are inherently better than relational databases; it is one way to represent and query a model with multiple engine variants.
Otavio Santana’s July 26, 2024, tutorial demonstrates the pattern with Jakarta NoSQL, JSON-B, Helidon, and Oracle NoSQL. Read the tutorial.
How the Java-to-document mapping works
Give the document an engine field
The sample’s Machine entity has an ID, an engine field, a manufacturer, and a year. The engine field is declared using the abstract Engine type and marked with a custom converter. That converter forms the persistence boundary: it translates between the Java field and the form the provider stores.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Record the subtype with a discriminator
The abstract Engine class uses JSON-B type metadata to name a property type and associate aliases with concrete classes: gas maps to GasEngine, and electric maps to ElectricEngine. A stored engine object can therefore carry a marker such as "type": "gas" or "type": "electric". When JSON-B reads the object, that marker identifies which subtype to instantiate; Java code can still work with the shared Engine abstraction.
Keep the converter provider-aware
The example separates subtype-aware JSON binding from persistence integration. JSON-B handles the subtype metadata, while the converter connects the Java value to the provider. The tutorial notes that a provider’s concrete representation may differ—for example, it could be a string, a Map<String, Object>, or BSON. Do not assume all Jakarta NoSQL providers use the same representation or converter behavior. See the tutorial’s converter and mapping example.
Query and retrieve by engine type
A discriminator can do more than guide deserialization: it can also be a queryable document property. The sample repository uses a query equivalent to:
Rank #2
from Machine where engine.type = :type
The parameter value selects the desired subtype, such as gas or electric. The REST resource in the example provides operations to list machines, retrieve one by ID, save a machine, and fetch machines by engine type. Sample payloads include the type marker and engine data such as horsepower; those payload values illustrate the schema rather than report real vehicle measurements. The query and resource examples are in the tutorial.
Run the tutorial’s local sample
The tutorial’s configuration uses a document database named machines, an Oracle NoSQL endpoint at http://localhost:8080, and a Helidon server port of 8181. It runs Oracle NoSQL Community Edition in Docker. The linked sample repository specifies JDK 21 for its build and run instructions and gives these commands:
-
Build the project:
mvn package -
Run the packaged application:
java -jar target/helidon.jar
These are the tutorial and repository’s sample instructions, not a guarantee of compatibility across every release of Jakarta NoSQL, Helidon, Oracle NoSQL, or their drivers. Check the versions and provider setup for the project you choose. The sample and its README are at helidon-oracle-json-types.
Check the API and database versions you choose
Jakarta NoSQL is an API standard for applications using NoSQL databases; it is not itself a database engine. The Eclipse Foundation’s specification page lists Jakarta NoSQL 1.0 as available and 1.1 as under development (page accessed September 30, 2026). Verify that your chosen API release, provider implementation, driver, and database version work together before adapting the sample. See the Jakarta NoSQL specification page.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Oracle’s product overview describes support for JSON, table, and key-value data types, as well as on-premises and cloud deployment; Oracle describes its Cloud Service as fully managed. The tutorial itself is local-first, so deploying beyond its Docker setup requires separate configuration for the chosen environment. See Oracle NoSQL Database Technical Overview.
Rank #4
Decide whether this document pattern fits your model
A discriminator-based document model is a practical option, not a universal replacement for relational inheritance or other persistence designs. Weigh the requirements that shape the application:
-
Subtype change frequency: Consider how often subtype-specific fields are added or changed and how those changes will affect existing documents.
-
Database-side querying: The example queries
engine.type. If consumers must filter or report on many subtype-specific fields, confirm that the provider and database support the query behavior you need.Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallSpecial offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.Best Value
-
Validation: Flexible document storage does not remove the need to validate required fields and allowed values for each subtype.
-
Database-specific features: A general API may help reduce coupling to a database’s native API, but can leave some provider-specific behavior outside the abstraction. A related discussion of Jakarta NoSQL describes APIs spanning key-value, column-family, document, and graph databases and makes that abstraction trade-off explicit: Jakarta NoSQL 1.0.0-b5: How To Make Your Life Easier Around Enterprise Java and NoSQL Databases.
-
Team and stack fit: Account for your team’s experience with the Java persistence stack and the operational requirements of the selected database.
The cited tutorial and sample demonstrate a mapping and query approach; they do not report a performance benchmark or establish that document storage is the right choice for every polymorphic model.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsQuick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

