Doma

May 8, 2026 · View on GitHub

Doma is a database access framework for Java with several notable strengths:

  • It checks and generates source code at compile time using annotation processing.
  • It supports associations between entities.
  • It offers a type-safe Criteria API.
  • It includes SQL templates, known as “two-way SQL.”
  • It runs independently, without relying on any other libraries.

Build Status javadoc project chat Twitter Ask DeepWiki

Backers

If you use Doma in your project or enterprise and would like to support ongoing development, please consider becoming a backer.

Supported by

JetBrains logo.


Prerequisite

The latest major version of Doma supports Java 17 and above. If you are using Java 8, please use Doma 2.

See also Major versions.

Supported databases

We are testing against the following databases:

Databaseversionstatus
H2 Database2.4.240stable
MySQL v55.7stable
MySQL v88.0.36stable
Oracle Database XE21cstable
PostgreSQL12.20stable
SQLite3.53.1.0stable
SQL Server2019stable

Examples

Type-safe Criteria API

This code uses a type-safe Criteria API to fetch employees from a specific department while establishing associations between the related entities:

var queryDsl = new QueryDsl(config);
var e = new Employee_();
var d = new Department_();

var employees = queryDsl
    .from(e)
    .innerJoin(d, on -> on.eq(e.departmentId, d.departmentId))
    .where(c -> c.eq(d.departmentName, "SALES"))
    .associate(e, d, (employee, department) -> {
        employee.setDepartment(department);
        department.getEmployeeList().add(employee);
    })
    .fetch();

See Unified Criteria API for more information.

SQL templates

This code uses an SQL template to fetch employees from a specific department while establishing associations between the related entities:

@Dao
public interface EmployeeDao {

  @Sql(
    """
    select
      /*%expand*/*
    from
      EMPLOYEE e
      inner join
      DEPARTMENT d
        on e.departmentId = d.departmentId
    where
      /*%if departmentName != null*/
      d.DEPARTMENT_NAME = /*departmentName*/'test'
      /*%end*/
    """)
  @Select(aggregateStrategy = EmployeeStrategy.class)
  List<Employee> selectByDepartmentName(String departmentName);

  @AggregateStrategy(root = Employee.class, tableAlias = "e")
  interface EmployeeStrategy {
    @AssociationLinker(propertyPath = "department", tableAlias = "d")
    BiFunction<Employee, Department, Employee> department = (e, d) -> {
      e.setDepartment(d);
      d.getEmployees().add(e);
      return e;
    };
  }
}

See SQL templates and Aggregate strategies for more information.

More Examples

Try Getting started and simple-examples.

Installing

Gradle

For Java projects:

plugins {
    id("org.domaframework.doma.compile") version "4.0.3"
}

dependencies {
    implementation("org.seasar.doma:doma-core:3.14.0")
    annotationProcessor("org.seasar.doma:doma-processor:3.14.0")
}

For Kotlin projects, use doma-kotlin instead of doma-core and use kapt in place of annotationProcessor:

plugins {
  id("org.domaframework.doma.compile") version "4.0.3"
}

dependencies {
    implementation("org.seasar.doma:doma-kotlin:3.14.0")
    kapt("org.seasar.doma:doma-processor:3.14.0")
}

Maven

We recommend using Gradle, but if you want to use Maven, see below.

For Java projects:

...
<properties>
    <doma.version>3.14.0</doma.version>
</properties>
...
<dependencies>
    <dependency>
        <groupId>org.seasar.doma</groupId>
        <artifactId>doma-core</artifactId>
        <version>${doma.version}</version>
    </dependency>
</dependencies>
...
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>17</source> <!-- depending on your project -->
                <target>17</target> <!-- depending on your project -->
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.seasar.doma</groupId>
                        <artifactId>doma-processor</artifactId>
                        <version>${doma.version}</version>
                    </path>
                </annotationProcessorPaths>
                <compilerArgs>
                    <!-- if you are using a Maven project in Eclipse, this argument is required -->
                    <arg>-Adoma.resources.dir=${project.basedir}/src/main/resources</arg>
                </compilerArgs>
            </configuration>
        </plugin>
    </plugins>
</build>

For Kotlin projects, see Kotlin document.

Documentation

https://doma.readthedocs.io/

Chatroom

https://domaframework.zulipchat.com

Major versions

Status and Repository

VersionStatusRepositoryBranch
Doma 1limited-supporthttps://github.com/seasarorg/doma/master
Doma 2limited-supporthttps://github.com/domaframework/doma/2.x
Doma 3stablehttps://github.com/domaframework/doma/master

Compatibility matrix

Doma 1Doma 2Doma 3
Java 6v
Java 7v
Java 8vv
Java 9v
Java 10v
Java 11v
Java 12v
Java 13v
Java 14v
Java 15v
Java 16v
Java 17vv
Java 18vv
Java 19vv
Java 20vv
Java 21vv
Java 22vv
Java 23v
Java 24v
Java 25v
Java 26v