Get Started

This guide covers the basic steps to integrate Litebridge into a Java project, from setting up dependencies to performing your first database operations.

1. Requirements

  • Java 21+: Leveraging modern features like records and pattern matching.
  • Maven: For dependency management and build automation.

2. Add Litebridge

Add the core ORM dependency to your pom.xml:

<dependency>
    <groupId>org.litebridgedb</groupId>
    <artifactId>litebridge-orm</artifactId>
    <version>0.4.0</version>
</dependency>

3. Choose a Provider

Include the artifact for your target database. Litebridge supports the following providers:

H2litebridge-db-h2
PostgreSQLlitebridge-db-postgres
Oraclelitebridge-db-oracle
SQLitelitebridge-db-sqlite

Example for PostgreSQL:

<dependency>
    <groupId>org.litebridgedbdb</groupId>
    <artifactId>litebridge-db-postgres</artifactId>
    <version>0.4.0</version>
</dependency>

4. Define an Entity

Map your Java classes to database tables using Litebridge annotations:

import org.litebridge.orm.annotation.Column;
import org.litebridge.orm.annotation.Table;

@Table("EXAMPLE.PERSON")
public class Person {

    @Column(value = "ID", generateUsingSequence = "PERSON_SEQ")
    private Long id;

    @Column("NAME")
    private String name;

    @Column("SURNAME")
    private String surname;

    // Getters and setters
}

Note: The Litebridge Maven plugin can automatically generate these entities from your database schema.

Plain, unaltered DTOs can also be used; see the Litebridge documentation for more details.

5. Initialize

Create a Litebridge instance and register your entities:

// Create a litebridgedb instance
Litebridge litebridge = new Litebridge(new PostgresDatabaseProvider(), dataSource);

// Register your entities
litebridge.register(Person.class);

6. Persistence & Queries

You are now ready to save and retrieve data using Litebridge's fluent API:

// Save an entity
litebridge.save(person);

// Query data
Optional<Person> alice = litebridge.select(Person.class)
    .where("name").eq("Alice")
    .first();

Next Steps

Explore the full functionality of Litebridge: