Module jakarta.nosql.core
Jakarta NoSQL is designed specifically for Java developers who need to build scalable, database-agnostic applications using NoSQL technologies. With Jakarta NoSQL, developers can seamlessly map Java objects to NoSQL databases using familiar paradigms, enabling them to focus on business logic without worrying about database-specific implementation details.
OverviewModern applications often require highly scalable and flexible storage solutions. NoSQL databases address these needs with their diverse data models (e.g., document, key-value, column-family, and graph). However, interacting with such databases in a type-safe, database-agnostic way has historically been challenging. Jakarta NoSQL solves this problem by offering:
- A standard API for NoSQL database interactions.
- Comprehensive support for mapping Java objects to NoSQL data models.
- Seamless integration with Java frameworks and runtime environments.
Jakarta NoSQL introduces several annotations to make it easier for Java developers to define mappings between Java objects and NoSQL databases. These include:
Entity
: Marks a class as a NoSQL entity, representing a top-level record in the database.Id
: Specifies the primary key or unique identifier for an entity.Column
: Maps a field or property to a column or attribute in the database.Convert
: Specifies a custom converter for handling complex or non-standard data types.Embeddable
: Denotes a reusable embedded structure for entities.DiscriminatorColumn
andDiscriminatorValue
: Enable inheritance mapping for NoSQL entities.MappedSuperclass
: Defines a superclass that provides shared mapping information for its subclasses.
Jakarta NoSQL was created with the following goals in mind:
- Standardization: Provide a consistent API across different NoSQL database types, enabling portability and reducing vendor lock-in.
- Ease of Use: Allow Java developers to interact with NoSQL databases using familiar paradigms like annotations and type-safe APIs.
- Flexibility: Support diverse NoSQL database models and allow developers to extend functionality through custom converters and mappings.
- Productivity: Reduce boilerplate code and simplify common operations like queries, updates, and object mapping.
- Object Mapping: Define how Java objects map to NoSQL database structures using annotations like
@Entity
,@Column
, and@Id
. - Custom Conversions: Handle complex data types with the
@Convert
annotation and theAttributeConverter
interface. - Inheritance Support: Use
@MappedSuperclass
,@DiscriminatorColumn
, and@DiscriminatorValue
to model entity inheritance. - Seamless Integration: Integrates with Java EE/Jakarta EE environments and modern frameworks, ensuring compatibility and ease of adoption.
Below is an example of a typical entity using Jakarta NoSQL annotations and a simple template integration to perform basic operations:
@Entity
public class Product {
@Id
private String id;
@Column
private String name;
@Column
private Category category;
}
public enum Category {
TECH, FOOD, CLOTHING
}
@Inject
private Template template;
public void performOperations() {
Product product = Product.builder().id("1").name("Laptop").category(Category.TECH).build();
// Insert operation
template.insert(product);
// Find operation
Optional<Product> foundProduct = template.find(Product.class, "1");
// Delete operation
template.delete(Product.class, "1");
List<Product> products = template.select(String.class).where("category").eq(Category.TECH).result();
}