Introduction
Changelog
Contact
Guides
Getting Started
Entities
Repositories
Queries & Specifications
Configuration & Pooling
Migrations
Spring Boot
Spigot & Paper Plugins
Recipes
Reference
Databases
Troubleshooting
Advanced
Multi-tenancy
Audit Trail
Testing
TrademarkTrademark
Ctrl k
Search…
Get started
Introduction
Changelog
Contact
Guides
Getting Started
Entities
Repositories
Queries & Specifications
Configuration & Pooling
Migrations
Spring Boot
Spigot & Paper Plugins
Recipes
Reference
Databases
Troubleshooting
Advanced
Multi-tenancy
Audit Trail
Testing
TrademarkTrademark© Aveiro. All rights reserved.
Built with Aveiro
Guide

Getting Started

Install JEHibernate and go from an empty project to a working repository, in a plugin, Spring Boot, or standalone Java.
Updated last month
Entities
This page takes you from nothing to a working repository three ways: a Spigot/Paper plugin, a Spring Boot service, and plain Java. All three share the same two steps — define an entity, define a repository — and differ only in how JEHibernate is started.

Install

Add the core module and a JDBC driver for your database. Prefer the jehibernate-bom to align all module versions with one import — see Databases. Maven and Groovy DSL coordinates use the same group and artifact.

Define an entity

Extend one of the base classes (LongIdEntity, UuidEntity, or StringIdEntity). They provide the id, automatic timestamps, and optimistic-locking version for you.

Define a repository

A repository is a class that extends AbstractCrudRepository<Entity, IdType>. Since 4.2 you can omit the Class<T> argument — the entity type is inferred.
dependencies {
    implementation("de.jexcellence.hibernate:jehibernate-core:4.2.0")

    // Pick the driver(s) you actually use:
    runtimeOnly("com.h2database:h2:2.5.252")            // embedded, dev/testing
    runtimeOnly("org.postgresql:postgresql:42.7.14")    // PostgreSQL
    runtimeOnly("com.mysql:mysql-connector-j:9.3.0")    // MySQL

    // Optional: enable schema migrations
    implementation("org.flywaydb:flyway-core:11.20.3")
}
@Entity
@Table(name = "players")
public class PlayerData extends UuidEntity {

    @Column(nullable = false)
    private String username;
    private long balance;

    protected PlayerData() {}   // required by JPA

    public PlayerData(UUID id, String username) {
        setId(id);
        this.username = username;
    }

    public String getUsername() { return username; }
    public long getBalance() { return balance; }
    public void setBalance(long balance) { this.balance = balance; }
}

Start it — standalone Java

Start it — Spigot / Paper plugin

The plugin module loads configuration from your data folder, so server admins can switch databases without a recompile.
Shading into a plugin
If you shade JEHibernate into your plugin jar, do NOT relocate org.slf4j — Paper already provides it. Relocating it without a provider prints 'No SLF4J providers were found' and drops all logs. See Troubleshooting.

Start it — Spring Boot

Add the starter and JEHibernate auto-configures against your application DataSource. No @Bean wiring.

Next steps

With a repository in hand, read Repositories for the full CRUD/async/batch surface, Queries & Specifications for composing filters, and Configuration & Pooling to tune HikariCP. If you deploy against an existing schema, read Migrations first — ddl-auto defaults to validate, so migrations own your tables.
public class PlayerRepository extends AbstractCrudRepository<PlayerData, UUID> {
    public PlayerRepository(ExecutorService executor, EntityManagerFactory emf) {
        super(executor, emf);
    }
}
var jeHibernate = JEHibernate.builder()
    .configuration(config -> config
        .database(DatabaseType.POSTGRESQL)
        .url("jdbc:postgresql://localhost:5432/app")
        .credentials("app", "secret")
        .ddlAuto("validate"))
    .scanPackages("com.example.domain")
    .build();

var players = jeHibernate.repositories().get(PlayerRepository.class);

var player = players.create(new PlayerData(uuid, "alice"));
var found  = players.findByIdOrThrow(uuid);

player.setBalance(1000);
players.save(player);

jeHibernate.close();   // shuts the pool down deterministically
var jeHibernate = JEHibernate.fromProperties(getDataFolder(), "database", "hibernate.properties");
var players = jeHibernate.repositories().get(PlayerRepository.class);

// Never block the main thread:
players.findByIdAsync(uuid).thenAccept(opt -> opt.ifPresent(this::greet));
implementation("de.jexcellence.hibernate:jehibernate-spring-boot:4.2.0")
# application.yml
spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/app
    username: app
    password: secret
jehibernate:
  database: POSTGRESQL
  ddl-auto: validate
  scan-packages: [com.example.domain]
  migration-enabled: false   # let Spring Boot's own Flyway run
@Service
class PlayerService {
    private final PlayerRepository players;
    PlayerService(JEHibernate jeHibernate) {           // auto-configured bean
        this.players = jeHibernate.repositories().get(PlayerRepository.class);
    }
}