Back to mapping overview

Annotated entities

Use annotations to map entities to tables declaratively.

Creating entities

Litebridge entities are classes decorated with annotations to define their mapping to tables and columns, and relationships with other entities.

Fields or property getter methods may be annotated.

Person.java / Account.java
import org.litebridge.orm.annotation.Column;
import org.litebridge.orm.annotation.Table;
import org.litebridge.orm.annotation.OneToMany;
// Person.java
@Table("LB.PERSON")
public class Person {

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

    @Column("NAME")
    private String name;

    @Column("SURNAME")
    private String surname;
    
    @OneToMany(mappedByField = "owner")
    private List<Account> accounts;

    // Getters and setters
}

// Account.java
@Table("LB.ACCOUNT")
public class Account {

    @Column(value = "ACCOUNT_ID", generateUsingSequence = "LB.ACCOUNT_SEQ")
    private Long id;
    
    @Column("ACCOUNT_NAME")
    private String name;
    
    @Column("BALANCE")
    private BigInteger balance;
    
    @Column(value = "PERSON_ID", joinUsing = true)
    private Person owner;
    
    // Getters and setters
}

Registering entities

Entities can be registered directly using the register method.

RegistrationExample.java
import org.example.entity.Person;
import org.example.entity.Account;
// Register a single entity
litebridge.register(Person.class);

// Register multiple entities
litebridge.register(Person.class, Account.class);