REST lifecycle

Lifecycle behavior belongs in service.rs and is implemented with QueryableRsListener<T>.

Callback annotations

Phase Callbacks

Fetch

@PreFetch, @PostFetch

List

@PreList, @PostList

Create

@PrePersist, @PostPersist

Update

@PreUpdate, @PostUpdate

Delete

@PreDelete, @PostDelete

A callback may accept:

  • no argument;

  • the entity;

  • the entity identifier;

  • List<T> for @PostList;

  • QueryableEvent<T> for access to all operation metadata.

Audit fields

@ApplicationScoped
public class DeveloperRsListener implements QueryableRsListener<Developer> {

    @Inject
    SecurityIdentity identity;

    @PrePersist
    void beforeCreate(Developer developer) {
        developer.creationDate = LocalDateTime.now();
        developer.creationUser = identity.getPrincipal().getName();
    }

    @PreUpdate
    void beforeUpdate(Developer developer) {
        Developer persisted = Developer.findById(developer.uuid);
        developer.creationDate = persisted.creationDate;
        developer.creationUser = persisted.creationUser;
        developer.updateDate = LocalDateTime.now();
        developer.updateUser = identity.getPrincipal().getName();
    }
}

The listener entity type is inferred from QueryableRsListener<Developer>, including through generic superclasses. Existing entityType() overrides remain supported.

Validation before create or update

Use the Queryable @PrePersist and @PreUpdate callbacks to validate the incoming entity before it is saved. Throw a Jakarta REST exception to reject the request with the corresponding HTTP status:

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.BadRequestException;

import io.quarkiverse.queryable.runtime.PrePersist;
import io.quarkiverse.queryable.runtime.PreUpdate;
import io.quarkiverse.queryable.runtime.QueryableRsListener;

@ApplicationScoped
public class CustomerRsListener implements QueryableRsListener<Customer> {
    @PrePersist
    @PreUpdate
    void validate(Customer customer) {
        if (customer.name == null || customer.name.isBlank()) {
            throw new BadRequestException("name is required");
        }
    }
}

An invalid POST or PUT returns HTTP 400 and the corresponding entity write is not performed. The REST framework controls the response body; use a Jakarta REST ExceptionMapper if your application requires a particular error format. Unmapped runtime exceptions are server errors, not validation responses. These are Queryable listener annotations, not the JPA lifecycle annotations with the same names.

Pre-callbacks execute before persistence and can reject or mutate the entity. Post-callbacks for write operations are registered as JTA synchronizations and run only after commit. Exceptions from post-callbacks are logged and cannot roll back a transaction that already committed.